问题
Here is the deal...
I want to make a program (exe) that will take the user defined settings and make a custom (exe) file for the user inside of the previously mentioned program (exe). Wanted to know if there was like a portable gcc or something?
Please be as detailed as possible, not really sure where to start with this one.
回答1:
The compiler itself is just another program which reads some input (source code) and writes some output (object code, or executable if it runs the linker too). You can use something like the system()
call to execute a compiler, for example with gcc:
system("g++ -o test test.cpp");
That will run the compiler (g++
), telling it to create an output file with a specific name (-o test
) using the named source file (test.cpp
).
回答2:
Your best bet for this is to use an embedded resource - then use e.g. BeginUpdateResource and related functions to modify a precreated EXE file. The MSDN overview of resources contains the information you need to add a RT_RCDATA
block to your EXE, retrieve its contents run-time, and modify its contents from another program.
来源:https://stackoverflow.com/questions/5689437/compile-cpp-file-to-exe-inside-of-programexe