4

enter image description here

I tried to download the SDL library from this particular link https://www.youtube.com/watch?v=PTQkCRxr6lk&t=194s .However I stumbled upon a "fatal error" and I have no clue what to do in order to solve it.

Here's what error I got:

1>------ Build started: Project: SDL2, Configuration: Release x64 ------
2>------ Skipped Build: Project: uninstall, Configuration: Release x64 ------
2>Project not selected to build for this solution configuration 
1>   Creating library D:/Media/Downloads/SDL2-2.0.10/Build/Release/SDL2.lib and object D:/Media/Downloads/SDL2-2.0.10/Build/Release/SDL2.exp
1>SDL_string.obj : error LNK2019: unresolved external symbol memset referenced in function SDL_vsnprintf_REAL
1>D:\Media\Downloads\SDL2-2.0.10\Build\Release\SDL2.dll : fatal error LNK1120: 1 unresolved externals
1>Done building project "SDL2.vcxproj" -- FAILED.
3>------ Skipped Build: Project: INSTALL, Configuration: Release x64 ------
3>Project not selected to build for this solution configuration 
========== Build: 0 succeeded, 1 failed, 4 up-to-date, 2 skipped ==========
Neri-kun
  • 173
  • 3
  • 14

2 Answers2

9

@Neri-kun I ran into exactly the same problem when building SDL2 on VS2019. It seems that memset is in vcruntime.dll, which is not included in CMakeLists.txt. So find the following part in CMakeLists.txt and add vcruntime to the EXTRA_LIBS. Problem solved:

   # Libraries for Win32 native and MinGW
-  list(APPEND EXTRA_LIBS user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 shell32)
+  list(APPEND EXTRA_LIBS vcruntime user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 shell32)
Kevin
  • 16,549
  • 8
  • 60
  • 74
  • What do you mean by following part?And regarding ```CMakeLists.txt```,here 's all that I found:```cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(IntelFortranImplicit Fortran) add_custom_command( OUTPUT output.cmake COMMAND ${CMAKE_COMMAND} -P ${IntelFortranImplicit_SOURCE_DIR}/detect.cmake ) add_library(FortranLib hello.f output.cmake)``` P.S:Sorry for responding after 10 days,I just postponed my project. – Neri-kun Oct 27 '19 at 22:31
  • 1
    As per the current release 2.0.10, there is one additional Windows-specific library to include, `setupapi`, so the line becomes: `list(APPEND EXTRA_LIBS vcruntime user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32)` – JPNotADragon Dec 29 '19 at 14:11
  • SDL 2.0.12 still has this issue. And adding vcruntime to the list makes it work. – edin-m Aug 26 '20 at 22:34
0

This is actually a compiler optimization issue. Something is inlining a call to memset inappropriately. If you inspect the SDL_string.c file, you will find that HAVE_MEMSET is not defined and therefore is not calling memset. The solution file provided in the VisualC folder does build Release configurations correctly. If you inspect the differences between the cmake generated solution and the one in the VisualC folder you should find that the cmake generated version inlines any suitable function while the one from the VisualC folder inlines only __inline marked up functions (/Ob1).