function which compile and build a VC program.

Posted on 2000-04-24
Medium Priority
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!
Question by:kanyuchun
  • 4
  • 4

Author Comment

ID: 2746744
Adjusted points from 100 to 200
LVL 22

Expert Comment

ID: 2747025
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.

Author Comment

ID: 2747263
Adjusted points from 200 to 300

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.


Author Comment

ID: 2747264
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!!!
LVL 22

Expert Comment

ID: 2747362
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.)

LVL 22

Expert Comment

ID: 2747394
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.

LVL 22

Accepted Solution

nietod earned 1200 total points
ID: 2747423
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.  

Author Comment

ID: 2749801
Thank you very much!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

864 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