Click here to Skip to main content
16,017,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Greetings & Kind Regards For a current project I require compiling C++ source via an invocation from a running C++ program for the purpose of determining if any C++ source files from a list of such files upon being altered by the program will still compile w/o error. The only way I know to invoke another program is via a call to system() e.g. system("compiler.exe target_C++_file.cpp"); However the compiler being invoked via the system() call is that from Visual Studio and requires a special Command Line Window specially prepared in some manner otherwise the system() call w/ compile argument fails. Therefor I seek advice on how to proceed i.e. to wit is there a C++ compiler which does not require a specially prepared Command Line Window or can the Visual Studio Developer's Command Prompt be invoked in some manner from within a running program and so execute the compiler from within it or of course some other solution to my problem. Thank You Kindly

What I have tried:

Attempted invoking batch file which invokes Visual Studio Developer's Prompt but it is amazingly complex and requires certain arguments which I do not know of. Duplicated all environment variables set by Visual Studio Developer's Prompt prior to invoking compiler invoked by system() but did not solve problem. Examined Boost compiler but according to site it requires same "Developer's Prompt".
Posted
Updated 3-Jan-23 18:20pm

1 solution

The simplest solution to to create a batch (or powershell) file which creates the environment the compiler needs in order to work, then run that from your application.

Most compilers just need environment variables to be set so they know where the library, include, and build tool files are - so open a VS Developers command prompt and see what it sets in the environment. Under the "<VisualStudio version root>\BuildTools\VC\Auxiliary\Build" folder in your VS installation there should be a number of .BAT files which set up everything the build(s) need - I'd start with those.

But ... do bear in mind that in order to work, every user will need to have VS both installed (potentially dangerous) and in the correct place in the file system as well as the same version!

What are you trying to do that you think you need this?
 
Share this answer
 
v2
Comments
BernardIE5317 4-Jan-23 0:34am    
Thank You for Your Kind Assistance
As for your first suggestion i.e. duplicate the environment via batch file that was my first attempt i.e. duplicate each environment variable via a batch file but problem persisted.

As for your second suggestion again that was my fist attempt.

As for your third paragraph I will deal with that after I find a way for the code to work on my machine.

As for your inquiry I am attempting to minimize my other projects' build times by automatically determining which headers need inclusion. The theory is once the correct order of all the headers is found to comment out each header separately starting from the bottom of the list then to attempt compile , if compiles w/o error that header is not needed and remains commented out , if compiles w/ error then the comment is removed and the header remains included , then to continue/loop in this fashion again starting from bottom of header include list until each header has been so processed.

I call your attention to suggestion provided here https://www.codeproject.com/Lounge.aspx?msg=5907173#xx5907173xx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900