Pelles C forum
Pelles C => Bug reports => Topic started by: Romashka on June 19, 2009, 11:33:59 PM
-
I'm writing a cross-platform library that is supposed to work on Windows, Linux, *BSD and Mac OS X.
Because Windows GUI applications require WinMain/wWinMain as the entry point, I've created a separate static lib file (a-la SDL_main.lib) that looks like this:
#include <windows.h>
extern int main(int argc, char *argv[]);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
. . .
// lpCmdLine is parsed to argc and argv
. .
main(argc, argv);
. . .
return 0;
}
Then an application that wants to link with my library needs to link with main.lib (on Windows only) but the main.c is the same on all platforms:
int main(int argc, char *argv[])
{
. . .
return 0;
}
This works as intended, and does not even require re#defining main() as SDL_main.{c,h} does,
nor it requires AL_END_OF_MAIN after main() as Allegro does.
But if I change WinMain to wWinMain:
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
- the linker fails:
POLINK: error: Unresolved external symbol '_WinMain@16'.
POLINK: fatal error: 1 unresolved external(s).
Any ideas why it looks for WinMain?
If this matters - I have UNICODE and _UNICODE defined.
-
Still an issue with v7.0
-
I think that is not a bug in polink.
That _WinMain@16 comes from crt when linking -subsystem:windows.
-
Yes, but wWinMain is defined, so polink should've used it IMHO.
The trick of having entry point in a separate static lib is what SDL 1.2 does, so it definitely works.
I've tried it in few other compilers and they used wWinMain from main.lib