Solved

function which compile and build a VC program.

Posted on 2000-04-24
8
214 Views
Last Modified: 2010-04-02
In a VC program, I want to compile and build other VC program.
Are there some vc function can do it ?
If there have that function,pls give a example for it.
If there have no such functin,pls tell me too.

thank you very much!
0
Comment
Question by:kanyuchun
  • 4
  • 4
8 Comments
 

Author Comment

by:kanyuchun
Comment Utility
Adjusted points from 100 to 200
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
In windows you can use CreateProcess() to run other programs.
You chould use this in various ways.

Your program could create a make file on disk (using an fstream object to write out he make file, for example), then you could use CreateProcess() to run nmake.exe

Or you could use CreateProcess() to run the compiler (cl.exe) and linker (link.exe) directly.

Its hard to give you more details than that, without knowing the details of what you are doing.  i.e. What files are beign compiled, what needs to be linked in.  What commandline options etc.

But those two approaches should get your started.  The first one is less direct, but actually might be easier as you don't have to worry about waiting for the compiler to finish before starting the linker.  (Which can be done but is more work.)

Let me know if you have more questions--and details.
0
 

Author Comment

by:kanyuchun
Comment Utility
Adjusted points from 200 to 300
0
 

Author Comment

by:kanyuchun
Comment Utility
Hi,nietod!
Thank you very much!
I reject your answer as I want to see a example so much!
Now I have a VC program named NN1, it have three class A1(A1.h and A1.cpp),A2(A2.h and A2.cpp),A3(A3.h and A3.cpp) and it should link two dll(d1.dll and d2.dll).
In my other VC program I want to complie and build my NN1.
Could you give me the codes and things I should do?
Thank you so much!!!
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
It is not necessary to reject an answer if you want to continue getting help from the expert.  Most problems are solved by a dialog between the expert and the client.

There is no way I can give you a complete example.  There are too many details that I don't know--only you know them.  I can get them started by you will have to work it out.

First of all, make sure you get these files to compile from a regular VC project.  i.e. make sure they have no syntax errors or other problems that will interfere.

Then I would try to do the stuff from the command line (DOS prompt).  That way you will learn what information you need to pass to the compiler and linker.  After that is determined, it is not to hard to pass the information to the compiler or linker with CreateProcess(), but learning what information needs to be passed is the hard part.

First, try using cl.exe to compile the three source code files (a1.cpp a2.cpp and a3.cpp)  Then use the link.exe to link them together into the DLL.  (I don't know how you want to get two DLLs from these.)

continues.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
The cl.exe program wil be located in a directory like "MSVC\VC98\BIN"

The cl.exe syntax is explained in the Vc help.  look up "CL syntax".

You will need to execute a command like

C:\MSVC\VC98\BIN\CL /c /GR /MD A1.CPP

/c - compiles but does not link
/GR - enables RTTI  (You can skip it if you don't use it.)
/MD - creates a mult-threaded DLL.  (use /MDd for a debug version.)

this should compile the a1.cpp file and create an a1.obj.   You may need to fool with these options and add and remove some.  You also might need to fool with the paths too.  (again I can only provide limited help here,  I just don't know the details of your situation.)

Once you get one to compile correctly, try to get the others to compile, they will probably use the same command line.

continues
0
 
LVL 22

Accepted Solution

by:
nietod earned 300 total points
Comment Utility
Once you have them compiled and have created the three .obj files from them, try to get them to link.  The linker shoudl be located in the same directory as cl.exe.  You can find its command-line syntax in the VC help by looking for LINK.EXE and then choosing "options list"

You will need to do something like

C:\MSVC\VC98\BIN\LINK /OUT:D1.DLL A1.OBJ A2.OBJ A3.OBJ

/OUT - Sets the name of the output file created  (D1.DLL).

Once you figure out these command lines, it will not be too hard to make things compiler from your program.   I may be able t help you figure out the command lines to some extent, but you will have to try things and tell me what errors you are getting, if any.  
0
 

Author Comment

by:kanyuchun
Comment Utility
hi,nietod!
Thank you very much!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now