Reputation: 57
I am trying to write a game similar to code hunt (https://www.codehunt.com/about.aspx) So How this will work, is the player can modify a .cpp file, which will be compiled and and ran within the code, but I have problems about how to compile it. I'am using the latest g++ compiler, and this is how I try to achive this:
void Builder::build(const char* file){
std::string s = "g++ ";
s += file;
s += " -o test.o";
system(s.c_str());
}
Where we get the .cpp file's name, and this code piece is supposed to build test.o This is just a test now, it might get more complex, I just wanted to test if the compiler will work within the code, but I get this error message when I try to run this:
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../libmingw32.a(main.o):(.text.startup+0xa7):undefined reference to 'WinMain@16'
collect2.exe: error: ld returned 1 exit status
PATH for mingw is set correctly, I checked. I am using Windows 8.1, g++ 4.9.3 and Code::Blocks.
Upvotes: 0
Views: 164
Reputation: 57
OK I'm an idiot, so the problem was that I was trying to build a file whitout a main function. This was deliberat design choice at first, but...well yeah. Sorry about that. Thank you Joachim Pileborg for leading me to it.
Upvotes: 0
Reputation: 409384
In Windows execution doesn't normally start at the main
functions, it starts at the WinMain
function, which takes some Windows-specific arguments. You should read e.g. this WinMain
reference for more information.
That some programs still seems to start at a main
function is because there is an object file linked with the program that contains the WinMain
function which calls your main
function.
Upvotes: 1