c++windowsbatch-filecommand-line

Batch file to compile a .cpp file on any PC


I am creating a program in which i need to compile and run a newly generated .cpp file, and in order to do that i have to create a batch file, which compiles and runs the .cpp file, and can easily be accessed trough system("run_cpp.cpp"). I can easily run the .cpp file trough the command line, but that's only when I'm using the MS visual studio command line OR setting up the environment using "VCVARS32.bat". BUT the goal is to make a program that works on any computer, and ANY computer doesn't have MS Visual Studio 2010.

So my question is :

How can i compile a .cpp file on any computer using command line (batch file). Are there maby some freeware compilators, that are easy addable to the project? Please help me out here!

Thanks in advance!

EDIT : I ment run_cpp.BAT not run_cpp.cpp sorry !


Solution

  • You could use gcc / gpp to compile your program. But then you will have to bundle the gnu toolchain with your program as well. or have it installed.

    In short this is not very feasible and running at run time generated code open a whole lot of security risks. Its never a good idea to do this. there are always other ways of solving you problem.
    You will also have no end of problems with enviroment settings