| Summary: | building SDL as a static library with static runtime doesn't compile/link with visual studio | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Wouter van Oortmerssen <aardappel> |
| Component: | build | Assignee: | norfanin |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | minor | ||
| Priority: | P2 | CC: | bulkmail, cdifan, gabomdq, madrazoman, norfanin |
| Version: | HG 2.0 | ||
| Hardware: | x86 | ||
| OS: | Windows 7 | ||
| Attachments: |
Adds a condition so only the MSVC 2012 compiler defines the macros for the functions of its version.
Fixes the version check for some functions that are only present with the MSVC 2013 CRT libraries. |
||
|
Description
Wouter van Oortmerssen
2013-04-23 20:41:00 UTC
(Sorry if you get a lot of copies of this email, we're touching dozens of bug reports right now.) Tagging a bunch of bugs as target-2.0.0, Priority 2. This means we're in the final stretch for an official SDL 2.0.0 release! These are the bugs we really want to fix before shipping if humanly possible. That being said, we don't promise to fix them because of this tag, we just want to make sure we don't forget to deal with them before we bless a final 2.0.0 release, and generally be organized about what we're aiming to ship. Hopefully you'll hear more about this bug soon. If you have more information (including "this got fixed at some point, nevermind"), we would love to have you come add more information to the bug report when you have a moment. Thanks! --ryan. I don't build in this configuration, but if you submit a tested patch to easily switch to static builds I'll be happy to include it. Thanks! I could submit a patch, which would basically consist of an #ifdef around the defines I mention in my original post. But I am afraid that is a hack, since I don't know enough about the SDL internals to know if this change makes sense, or there is something more obvious going wrong elsewhere. If you just try to build in VS statically, you might be able to see why it is not compiling. Also, I don't use Mercurial, I may not have time to set this up any time soon. Okay, I'll take a look at this sometime after the 2.0 release. Thanks! I very nearly have SDL2 working as a static library. I am currently using CMake with "-DDIRECTX=OFF" set, and there are only a few modifications required. First, I need "/MT" instead of "/MD" as well, which I had trouble automating through CMake. As a result, I temporarily have modified it myself, changing "MultiThreadedDLL" to "MultiThreaded" and "MultiThreadedDebugDLL" to "MultiThreadedDebug" in the vcxproj file. Second, there are two symbols defined by /stdlib/SDL_stdlib.c which create a conflict in my project. These are "_fltused" and "_ftol2_sse", which I temporarily commented out. Setting HAVE_LIBC caused a host of errors for me. Third, I needed additional libs linked in my DLL. These include: "winmm.lib", "imm32.lib", "ole32.lib", "oleaut32.lib", and "version.lib", in addition to "gdi32.lib", "opengl32.lib", "user32.lib", "wldap32.lib" and "shell32.lib" which were already linked. Now one problem remains. I have one problem when linking: LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol _main reference d in function ___tmainCRTStartup What would be the fix? Joshua, you need to link in SDL_main probably. Also, one of our GSOC projects may interest you, and feedback there is always appreciated. https://bitbucket.org/gsocben/sdl-gsoc-2013 I am trying to link SDL2 into another static library, I'm sorry that I didn't mention this. As a result, I would expect that there should be no reference to "main" yet, since it isn't an application, but a library? I have SDL 2.0.0 building and as a static library. Everything seems to work so far, but I'm just starting to work with SDL... I used the following steps: 1) Ensuring that HAVE_LIBC is defined to avoid link conflicts with the standard library. I'm doing that via the project configuration. 2) Uncommenting the following #define's in SDL_config_windows.h: - HAVE_STRTOLL - HAVE_SSCANF - HAVE_M_PI - HAVE_COPYSIGN - HAVE_SCALBN This is with Visual Studio 2010 Professional, in particular step 2 may be different depending on VS version. I'm using /MT. Created attachment 1341 [details]
Adds a condition so only the MSVC 2012 compiler defines the macros for the functions of its version.
Attaching a patch that adds a condition so that the HAVE_X supported by MSVC 2012 only get defined with that compiler. MSVC 2008 and 2010 will then build without any modification to the SDL source code.
Also moved HAVE_M_PI to a separate check. The Microsoft headers require _USE_MATH_DEFINES to be defined before they define the constants.
Your patch looks good, thanks! http://hg.libsdl.org/SDL/rev/2f67f0616044 Created attachment 1365 [details]
Fixes the version check for some functions that are only present with the MSVC 2013 CRT libraries.
I did my testing wrong and failed to see that 2012 doesn't have these functions. Microsoft implemented them in their upcoming 2013 version, though. The attached patch changes it to the check for the next version.
I also removed the HAVE_ITOA because that would require linking with oldnames.lib and it's easier to just let the SDL implementation take over.
Fixed, thanks! http://hg.libsdl.org/SDL/rev/c50a384be081 |