We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5384

Summary: dll exports broken in current hg
Product: SDL Reporter: Ozkan Sezer <sezeroz>
Component: buildAssignee: Ozkan Sezer <sezeroz>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2 Keywords: target-2.0.14
Version: HG 2.0   
Hardware: All   
OS: Windows (All)   
Attachments: DLL_EXPORT patch

Description Ozkan Sezer 2020-12-08 20:18:45 UTC
This commit https://hg.libsdl.org/SDL/rev/be0a46c9b010 (taken from
https://github.com/microsoft/vcpkg/tree/master/ports/sdl2/) is wrong
and also problematic.

The _DLL macro usually is defined by MSVC dll projects, but it is not
defined by our MSVC project files because it has not been needed. The
autotools builds define DLL_EXPORT by way of libtool, but begin_code.h
doesn't check it. The result is: the autotools builds now export all
and every symbol it can find.

Solution would be defining DLL_EXPORT in CMake and MSVC project files
and changing _DLL to DLL_EXPORT in begin_code.h.  Also, the satellite
projects such as SDL_mixer should be tested with any changes.

Or: We can revert the commit to happily go back to old behavior.
Comment 1 Sam Lantinga 2020-12-08 22:27:20 UTC
Let's go ahead and switch the projects to define DLL_EXPORT. Thanks for catching that!
Comment 2 Ozkan Sezer 2020-12-09 00:40:50 UTC
Created attachment 4556 [details]
DLL_EXPORT patch

Here is an initial patch, which does the following.  Please review.

begin_code.h (DECLSPEC):  Remove BORLANDC support.  Change __declspec(dllexport)
  condition from _DLL to DLL_EXPORT.
- Question: Should we add __CYGWIN__ there along with __WINDOWS__ and __WINRT__?

CMakeLists.txt (SDL2 SHARED): Add DLL_EXPORT define.

VisualC/SDL/SDL.vcxproj (ClCompile -> PreprocessorDefinitions): add DLL_EXPORT

TODO: VisualC-WinRT projects: There are three projects there. Should I do the
  same with VisualC? (All those three build DLLs, right?)

Build-tested with:
- autotools (configure), targeting x86_64-w64-mingw32
- cmake, targeting x86_64-w64-mingw32
- VS2017, x86/x64 Release and Debug configurations
Comment 3 Sam Lantinga 2020-12-09 02:49:53 UTC
Yes, the WinRT projects should define this as well. No, I don't think we should check __CYGWIN__, I think that's used for the UNIX emulation layer.
Comment 4 Sam Lantinga 2020-12-09 02:50:19 UTC
(In reply to Sam Lantinga from comment #3)
> Yes, the WinRT projects should define this as well. No, I don't think we
> should check __CYGWIN__, I think that's used for the UNIX emulation layer.

Actually, yes, we should check __CYGWIN__, since it uses the Win32 DLL toolchain.
Comment 5 Sam Lantinga 2020-12-09 06:15:09 UTC
I think this is the last thing we're waiting on for the SDL 2.0.14 release candidate build, so go ahead and commit when you're ready and let me know when you're done.

Thanks!
Comment 6 Ozkan Sezer 2020-12-09 09:04:52 UTC
(In reply to Sam Lantinga from comment #5)
> I think this is the last thing we're waiting on for the SDL 2.0.14 release
> candidate build, so go ahead and commit when you're ready and let me know
> when you're done.
> 
> Thanks!

Pushed https://hg.libsdl.org/SDL/rev/849e9a72cfff
Comment 7 Ozkan Sezer 2020-12-09 09:07:12 UTC
(In reply to Sam Lantinga from comment #5)
> I think this is the last thing we're waiting on for the SDL 2.0.14 release
> candidate build, 

Make sure to check bug #5253 before doing 2.0.14

Closing this one.