Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

function which compile and build a VC program.

Posted on 2000-04-24
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need some help with listview limit text 20 112
C Language combined operators 28 115
C++ finding a sting in a char* string from a text file 3 120
Dynamically allocate memory 9 63
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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

829 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