| Summary: | SDL fails to link when CMake is used with VS2015 | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Alex Szpakowski <amaranth72> |
| Component: | build | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | gygax |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Windows (All) | ||
| Attachments: | Conditionally add libraries needed by Visual Studio 2015 | ||
|
Description
Alex Szpakowski
2015-07-30 00:00:58 UTC
Created attachment 2340 [details]
Conditionally add libraries needed by Visual Studio 2015
Also removed dxerr.lib and dxerr8.lib.
SDL is supposed to avoid dependencies on the Visual C runtime libraries, I believe.
I have some local changes to the CMakeLists.txt file which fix the issues for me, but I'll probably need to clean them up (and make sure they don't do anything unintentional) before committing them. The changes are:
if(MSVC)
# Don't try to link with the default set of libraries.
set_target_properties(SDL2 PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
set_target_properties(SDL2 PROPERTIES LINK_FLAGS_DEBUG "/NODEFAULTLIB")
set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
# Prevent codegen that would use the VC runtime libraries.
add_definitions(/arch:SSE /GS-)
# Make sure /RTC1 is disabled, otherwise it will use functions from the CRT
foreach(flag_var
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
string(REGEX REPLACE "/RTC(su|[1su])" "" ${flag_var} "${${flag_var}}")
endforeach(flag_var)
endif()
(although they aren't all grouped together in my local copy of the file.)
Thanks Alex, the DLL builds perfectly with your changes. (I was completely unaware of buffer overrun detection and its implications.) So, two things to do: 1) add in your settings 2) remove references to dxerr.lib and dxerr8.lib How can we make sure these changes make it into the official source ? Is dxerr not used at all in recent SDL versions? Once I'm completely satisfied with my changes I'll commit them to SDL's repository. It builds without dxerr.lib or dxerr8.lib. Also, about a year ago I searched the code for calls to dxerr functions, and found a few, which were however all commented out. I pushed my fixes: https://hg.libsdl.org/SDL/rev/d3e4f7b44d4d There was a separate commit which changed the dxerr stuff to only link in more limited circumstances: https://hg.libsdl.org/SDL/rev/e3d651c5fe31 |