[Commits] SDL: Fixed bug 4034 - Do we really need _DllMainCRTStartup() in ...

libsdl.org revision control commits-owner at libsdl.org
Sun Feb 18 08:57:03 PST 2018

details:   https://hg.libsdl.org/SDL/rev/0ee27779b86f
changeset: 11882:0ee27779b86f
user:      Sam Lantinga <slouken at libsdl.org>
date:      Sun Feb 18 08:57:01 2018 -0800
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:

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 |  6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)

diffs (21 lines):

diff -r ecddbd9fe6b5 -r 0ee27779b86f src/SDL.c
--- a/src/SDL.c	Sat Feb 17 23:57:57 2018 -0500
+++ b/src/SDL.c	Sun Feb 18 08:57:01 2018 -0800
@@ -451,9 +451,7 @@
-#if defined(__WIN32__)
-#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
+#if defined(__WIN32__) && defined(__WATCOMC__) && defined(BUILD_DLL)
 /* Need to include DllMain() on Watcom C for some reason.. */
@@ -471,6 +469,4 @@
 #endif /* building DLL with Watcom C */
-#endif /* __WIN32__ */
 /* vi: set sts=4 ts=4 sw=4 expandtab: */

More information about the commits mailing list