I have a windows project that does not include a WinMain function. WinMain is in a static library that is linked to the project.
When I link the program, I get an error for "Undefined reference to WinMain". Is there a way to link leaving WinMain in the library? Or will I have to include it in one of the main object modules?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you're right, extern "C" has no effect, because WinMain is already declared as extern "C" in winbase.h
however, it doesn't get linked to your program because it is not referenced
to reference it, it is enough to write something like:
void dummy(){WinMain(0,0,0,0);}
somewhere in your main program files; you don't need to ever call the dummy function
I think you could even make it inline and put it in a header file that you include
Adrian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a windows project that does not include a WinMain function. WinMain is in a static library that is linked to the project.
When I link the program, I get an error for "Undefined reference to WinMain". Is there a way to link leaving WinMain in the library? Or will I have to include it in one of the main object modules?
if you define WinMain in a cpp file, it might be worth trying to declare it as extern "C"
Adrian
I tried defining it as extern "C". It did the same thing.
you're right, extern "C" has no effect, because WinMain is already declared as extern "C" in winbase.h
however, it doesn't get linked to your program because it is not referenced
to reference it, it is enough to write something like:
void dummy(){WinMain(0,0,0,0);}
somewhere in your main program files; you don't need to ever call the dummy function
I think you could even make it inline and put it in a header file that you include
Adrian
Check your linking order. Make sure you are linking with your WinMain containing lib before mingw tries to link in its runtime libs.
Kip
The dummy function did it.
Thanks.