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 5112

Summary: CMake won't compile in VS2019 (patch included)
Product: SDL Reporter: dark_sylinc
Component: *don't know*Assignee: Sam Lantinga <slouken>
Status: WAITING --- QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, martin.gerhardy, tom.hultonharrop
Version: 2.0.13Keywords: target-2.0.14
Hardware: x86_64   
OS: Windows 10   
Attachments: Patch
Patch v2

Description dark_sylinc 2020-04-27 02:09:04 UTC
Created attachment 4323 [details]
Patch

Trying to build SDL with VS2019 using CMake will encounter a linking error

More specifically:

    1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL


It seems memcpy call needs vcruntime library.

The attached patch fixes the error. This patch was tested against VS2019.

More details here:

https://stackoverflow.com/questions/58288692/cant-build-solution-in-release-mode-for-sdl-library-on-vs-2019
Comment 1 dark_sylinc 2020-04-27 02:25:25 UTC
DO NOT USE THIS PATCH

After looking into:

https://developercommunity.visualstudio.com/content/problem/711317/unexpected-implicit-memset-in-release-optimized-bu.html

It would seem SDL does as much as possible to avoid the CRT; and it already uses  #pragma function() in src/stdlib/SDL_stdlib.c but it does not do that with memset.
Comment 2 dark_sylinc 2020-04-27 03:00:45 UTC
Created attachment 4324 [details]
Patch v2

New fix to the problem, without linking to libc
Comment 3 Alex Szpakowski 2020-05-01 21:38:30 UTC
I worked around this problem in a different manner: https://github.com/love2d/megasource/commit/7ed6273a1a8e913157236cd18a0de46fd029a447

I'm not sure which way is better.
Comment 4 Sam Lantinga 2020-05-02 21:43:55 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/d5fe4ad4d29c
Comment 5 Martin Gerhardy 2020-05-06 18:04:20 UTC
Now the reverse is happening. Without that revision everything links fine
----------------------------------------------------------------
2020-05-06T15:14:11.7285275Z libvcruntimed.lib(memcpy.obj) : error LNK2005: memcpy already defined in sdl2.lib(SDL_stdlib.obj) [D:\a\engine\engine\build\src\modules\voxelutil\tests-voxelutil.vcxproj]


Github Actions output for the version:
----------------------------------------------------------------
2020-05-06T14:53:25.8733456Z Microsoft Windows Server 2019
2020-05-06T14:53:25.8733674Z 10.0.17763
2020-05-06T14:53:25.8734418Z Environment: windows-2019
2020-05-06T14:53:25.8734599Z Version: 20200426.1
2020-05-06T14:53:25.8734923Z Included Software: https://github.com/actions/virtual-environments/blob/win19/20200426.1/images/win/Windows2019-Readme.md
Comment 6 Ozkan Sezer 2020-11-08 19:53:15 UTC
*** Bug 5334 has been marked as a duplicate of this bug. ***
Comment 7 Sam Lantinga 2020-11-09 07:27:15 UTC
Okay, we need to not define memset() and memcpy() in SDL. I want to fix this for 2.0.14.
Comment 8 Sam Lantinga 2020-12-09 03:08:02 UTC
It turns out that we do need to define memset and memcpy in SDL to handle compiler intrinsic optimization.

Can you check the latest SDL snapshot and make sure it works for your scenarios?
http://www.libsdl.org/tmp/SDL-2.0.zip

Thanks!