Link to home
Start Free TrialLog in
Avatar of kanyuchun
kanyuchun

asked on

function which compile and build a VC program.

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!
Avatar of kanyuchun
kanyuchun

ASKER

Adjusted points from 100 to 200
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.
Adjusted points from 200 to 300
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!!!
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.
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
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi,nietod!
Thank you very much!