Fixed bug 4034 - Do we really need _DllMainCRTStartup() in every Windows build?
authorSam Lantinga <slouken@libsdl.org>
Sun, 18 Feb 2018 08:57:01 -0800
changeset 118820ee27779b86f
parent 11881 ecddbd9fe6b5
child 11883 d20126d8d014
Fixed bug 4034 - Do we really need _DllMainCRTStartup() in every Windows build?

Andreas Falkenhahn

In src/SDL.c there is this code:

_DllMainCRTStartup(HANDLE hModule,

...

The comment says that this is needed on Watcom C for some reason but why is it included then when building with Visual C as well? Shouldn't it be only included when compiling on Watcom C then?

I'm asking because this code caused me a lot of headaches because I'm building a DLL that contains SDL and I link using /MT and the _DllMainCRTStartup() symbol obviously led to lots of trouble but it wasn't clear to me where the problem was because all I got from the linker was:

LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup

So I had to got through each and every object to see what the culprit was. See here for the full story:
https://stackoverflow.com/questions/25067151/lnk2019-unresolved-external-symbol-main-referenced-in-function-tmaincrtstar/48177067#48177067

So if it isn't necessary on Visual C, please just leave that symbol out on Visual C so that it no longer leads to any trouble. Thanks.
src/SDL.c
     1.1 --- a/src/SDL.c	Sat Feb 17 23:57:57 2018 -0500
     1.2 +++ b/src/SDL.c	Sun Feb 18 08:57:01 2018 -0800
     1.3 @@ -451,9 +451,7 @@
     1.4  #endif
     1.5  }
     1.6  
     1.7 -#if defined(__WIN32__)
     1.8 -
     1.9 -#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
    1.10 +#if defined(__WIN32__) && defined(__WATCOMC__) && defined(BUILD_DLL)
    1.11  /* Need to include DllMain() on Watcom C for some reason.. */
    1.12  
    1.13  BOOL APIENTRY
    1.14 @@ -471,6 +469,4 @@
    1.15  }
    1.16  #endif /* building DLL with Watcom C */
    1.17  
    1.18 -#endif /* __WIN32__ */
    1.19 -
    1.20  /* vi: set sts=4 ts=4 sw=4 expandtab: */