NO

Author Topic: Linker searches for WinMain when wWinMain is defined  (Read 5178 times)

Romashka

  • Guest
Linker searches for WinMain when wWinMain is defined
« 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:
Code: [Select]
#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:
Code: [Select]
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:
Code: [Select]
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)- the linker fails:
Code: [Select]
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.

Romashka

  • Guest
Re: Linker searches for WinMain when wWinMain is defined
« Reply #1 on: January 27, 2014, 12:19:56 PM »
Still an issue with v7.0

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: Linker searches for WinMain when wWinMain is defined
« Reply #2 on: January 27, 2014, 01:22:13 PM »
I think that is not a bug in polink.
That _WinMain@16 comes from crt when linking -subsystem:windows.

May the source be with you

Romashka

  • Guest
Re: Linker searches for WinMain when wWinMain is defined
« Reply #3 on: January 28, 2014, 02:45:07 PM »
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