0

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 !

krishkule
  • 79
  • 4
  • 12
  • Windows does not come with a C++ compiler. So you will need to install one. – David Heffernan Apr 17 '12 at 11:28
  • Could you not compile it and distribute the exe rather than the .cpp file? – Bali C Apr 17 '12 at 11:31
  • 2
    Sounds like a solution looking for a problem to me. Context? – Robinson Apr 17 '12 at 11:32
  • 1
    Why are you trying to do something like that? A free compiler is gcc btw. – W. Goeman Apr 17 '12 at 11:33
  • 1
    Don't. Seriously, don't. If `system("foo.cpp")` works, it means that you have stolen the association of `.cpp`. That's 100% unacceptable. – MSalters Apr 17 '12 at 11:38
  • : I ment run_cpp.BAT not run_cpp.cpp sorry ! The thing is, i am creating the .cpp while running a different one, so i need to compile to get an exe... http://stackoverflow.com/questions/10173694/how-to-generate-and-compile-c-code-while-the-program-is-running here is the thing i am making if anything : – krishkule Apr 17 '12 at 12:38
  • The natural solution is to use the command line ftp (I checked, it's still there in Windows 7) to upload the source file to a server that compiles it, and download the exe in small pieces (to prevent Windows from understanding what it is and adding "security") which you then copy /b concatenate. The only problem with that is that you need the server and the user needs an Internet connection. But hey, who said it would be *easy*! – Cheers and hth. - Alf Apr 17 '12 at 12:55
  • What does the generated C++ program do? Does it have to be in C++? If the target machines have the .NET framework installed, then the C# compiler will be available. – Ferruccio Apr 17 '12 at 14:05

1 Answers1

0

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

Sibster
  • 3,081
  • 21
  • 18