| Summary: | Error using static | ||
|---|---|---|---|
| Product: | SDL | Reporter: | MailMr_S |
| Component: | *don't know* | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | frank.richter, sezeroz |
| Version: | HG 2.1 | ||
| Hardware: | x86_64 | ||
| OS: | Windows 7 | ||
| Attachments: | Patch to inhibit dllexport for Windows static lib | ||
Created attachment 4455 [details]
Patch to inhibit dllexport for Windows static lib
Hi,
the attached patch addresses (part) of the initial comment by removing __declspec(dllexport) from static builds.
This means the SDL symbols are not exported any more when a static version is used. With that the linker can remove unused SDL symbols.
About setting "dllexport" only when building, and "dllimport" when consuming:
This would be best... however, I tried the approach by defining and checking for "BUILD_SDL", and I found that currently breaks addon libs (eg SDL_mixer), as they use DECLSPEC as well. They would have to be updated to define BUILD_SDL.
And, in practice, having "dllexport" on a symbol even if that is defined in some lib works fine (at least on VS).
This should be fixed in SDL2-2.0.14 |
I've tried to build an use a static version from HG with CMake and VS2015. Building is fine, but I've a lot of problems using the lib in other projects. I found something interesting in begin_code.h /* Some compilers use a special export keyword */ #ifndef DECLSPEC # if defined(__WIN32__) || defined(__WINRT__) # ifdef __BORLANDC__ # ifdef BUILD_SDL # define DECLSPEC # else # define DECLSPEC __declspec(dllimport) # endif # else # define DECLSPEC __declspec(dllexport) # endif # elif defined(__OS2__) # ifdef BUILD_SDL # define DECLSPEC __declspec(dllexport) # else # define DECLSPEC # endif # else # if defined(__GNUC__) && __GNUC__ >= 4 # define DECLSPEC __attribute__ ((visibility("default"))) # else # define DECLSPEC # endif # endif #endif /* By default SDL uses the C calling convention */ #ifndef SDLCALL #if (defined(__WIN32__) || defined(__WINRT__)) && !defined(__GNUC__) #define SDLCALL __cdecl #elif defined(__OS2__) || defined(__EMX__) #define SDLCALL _System # if defined (__GNUC__) && !defined(_System) # define _System /* for old EMX/GCC compat. */ # endif #else #define SDLCALL #endif #endif /* SDLCALL */ I'm sure that __declspec(dllexport) is only accepted on creating a shared library on Windows. In case of linking this library it should be __declspec(dllimport). On building/linking a static library DECLSPEC should be set to nothing.