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!
Who is Participating?
nietodConnect With a Mentor Commented:
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


/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.  
kanyuchunAuthor Commented:
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.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

kanyuchunAuthor Commented:
Adjusted points from 200 to 300
kanyuchunAuthor Commented:
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.)

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 - 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.

kanyuchunAuthor Commented:
Thank you very much!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.