libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.36k stars 1.74k forks source link

SDL2-static.lib(SDL_stdlib.obj) : error LNK2005: memset already defined in vcruntime.lib(VCRUNTIME140.dll) #4258

Closed ab503044120 closed 3 years ago

ab503044120 commented 3 years ago
Build started...
1>------ Build started: Project: ZERO_CHECK, Configuration: Release x64 ------
1>Checking Build System
2>------ Build started: Project: SDL2main, Configuration: Release x64 ------
3>------ Build started: Project: SDL2-static, Configuration: Release x64 ------
4>------ Build started: Project: SDL2_test, Configuration: Release x64 ------
2>Building Custom Rule E:/PERSON/code/Player/third_lib/SDL/CMakeLists.txt
3>Building Custom Rule E:/PERSON/code/Player/third_lib/SDL/CMakeLists.txt
4>Building Custom Rule E:/PERSON/code/Player/third_lib/SDL/CMakeLists.txt
2>SDL_windows_main.c
4>SDL_test_assert.c
3>SDL.c
4>SDL_test_common.c
4>SDL_test_compare.c
4>SDL_test_crc32.c
3>SDL_assert.c
4>SDL_test_font.c
4>E:\PERSON\code\Player\third_lib\SDL\src\test\SDL_test_font.c(1048,1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
4>E:\PERSON\code\Player\third_lib\SDL\src\test\SDL_test_font.c(2104,1): warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
4>SDL_test_fuzzer.c
4>SDL_test_harness.c
3>SDL_dataqueue.c
4>SDL_test_imageBlit.c
3>SDL_error.c
2>SDL2main.vcxproj -> E:\PERSON\code\Player\third_lib\SDL\out\Release\SDL2main.lib
3>SDL_hints.c
3>SDL_log.c
4>SDL_test_imageBlitBlend.c
3>E:\PERSON\code\Player\third_lib\SDL\src\SDL_log.c(379,71): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data
3>E:\PERSON\code\Player\third_lib\SDL\src\SDL_log.c(387,68): warning C4267: 'function': conversion from 'size_t' to 'DWORD', possible loss of data
4>SDL_test_imageFace.c
4>SDL_test_imagePrimitives.c
3>SDL_atomic.c
3>SDL_spinlock.c
4>SDL_test_imagePrimitivesBlend.c
3>SDL_audio.c
4>SDL_test_log.c
4>SDL_test_md5.c
3>SDL_audiocvt.c
4>SDL_test_memory.c
4>SDL_test_random.c
3>SDL_audiodev.c
4>Generating Code...
3>SDL_audiotypecvt.c
3>SDL_mixer.c
3>SDL_wave.c
3>SDL_cpuinfo.c
3>SDL_dynapi.c
3>SDL_clipboardevents.c
3>SDL_displayevents.c
4>SDL2_test.vcxproj -> E:\PERSON\code\Player\third_lib\SDL\out\Release\SDL2_test.lib
4>Done building project "SDL2_test.vcxproj".
3>SDL_dropevents.c
3>SDL_events.c
3>Generating Code...
3>Compiling...
3>SDL_gesture.c
3>SDL_keyboard.c
3>SDL_mouse.c
3>SDL_quit.c
3>SDL_touch.c
3>SDL_windowevents.c
3>SDL_rwops.c
3>SDL_haptic.c
3>e_atan2.c
3>e_exp.c
3>e_fmod.c
3>e_log.c
3>e_log10.c
3>e_pow.c
3>e_rem_pio2.c
3>e_sqrt.c
3>k_cos.c
3>k_rem_pio2.c
3>k_sin.c
3>k_tan.c
3>Generating Code...
3>Compiling...
3>s_atan.c
3>s_copysign.c
3>s_cos.c
3>s_fabs.c
3>s_floor.c
3>s_scalbn.c
3>s_sin.c
3>s_tan.c
3>SDL_locale.c
3>SDL_url.c
3>SDL_power.c
3>SDL_d3dmath.c
3>SDL_render.c
3>SDL_yuv_sw.c
3>SDL_render_d3d.c
3>SDL_shaders_d3d.c
3>SDL_render_d3d11.c
3>SDL_shaders_d3d11.c
3>SDL_render_gl.c
3>SDL_shaders_gl.c
3>Generating Code...
3>Compiling...
3>SDL_render_gles.c
3>SDL_render_gles2.c
3>SDL_shaders_gles2.c
3>SDL_render_psp.c
3>SDL_blendfillrect.c
3>SDL_blendline.c
3>SDL_blendpoint.c
3>SDL_drawline.c
3>SDL_drawpoint.c
3>SDL_render_sw.c
3>SDL_rotate.c
3>SDL_render_gles2vita.c
3>SDL_shaders_gles2vita.c
3>SDL_render_vita_gxm.c
3>SDL_render_vita_gxm_memory.c
3>SDL_render_vita_gxm_tools.c
3>SDL_sensor.c
3>SDL_crc32.c
3>SDL_getenv.c
3>SDL_iconv.c
3>Generating Code...
3>Compiling...
3>SDL_malloc.c
3>SDL_qsort.c
3>SDL_stdlib.c
3>SDL_string.c
3>SDL_strtokr.c
3>SDL_thread.c
3>SDL_timer.c
3>SDL_RLEaccel.c
3>SDL_blit.c
3>SDL_blit_0.c
3>SDL_blit_1.c
3>SDL_blit_A.c
3>SDL_blit_N.c
3>SDL_blit_auto.c
3>SDL_blit_copy.c
3>SDL_blit_slow.c
3>SDL_bmp.c
3>SDL_clipboard.c
3>SDL_egl.c
3>SDL_fillrect.c
3>Generating Code...
3>Compiling...
3>SDL_pixels.c
3>SDL_rect.c
3>SDL_shape.c
3>SDL_stretch.c
3>SDL_surface.c
3>SDL_video.c
3>SDL_vulkan_utils.c
3>SDL_yuv.c
3>yuv_rgb.c
3>SDL_gamecontroller.c
3>SDL_joystick.c
3>SDL_dummyaudio.c
3>SDL_diskaudio.c
3>SDL_virtualjoystick.c
3>SDL_nullevents.c
3>SDL_nullframebuffer.c
3>SDL_nullvideo.c
3>SDL_hid.c
3>SDL_windows.c
3>SDL_xinput.c
3>Generating Code...
3>Compiling...
3>SDL_sysurl.c
3>SDL_winmm.c
3>E:\PERSON\code\Player\third_lib\SDL\src\audio\winmm\SDL_winmm.c(97,1): warning C4244: '=': conversion from 'WORD' to 'Uint8', possible loss of data
3>E:\PERSON\code\Player\third_lib\SDL\src\audio\winmm\SDL_winmm.c(98,1): warning C4244: '=': conversion from 'WORD' to 'Uint8', possible loss of data
3>SDL_directsound.c
3>SDL_wasapi.c
3>E:\PERSON\code\Player\third_lib\SDL\src\audio\wasapi\SDL_wasapi.c(140,42): warning C4244: '=': conversion from 'WORD' to 'Uint8', possible loss of data
3>SDL_wasapi_win32.c
3>SDL_windowsclipboard.c
3>SDL_windowsevents.c
3>SDL_windowsframebuffer.c
3>SDL_windowskeyboard.c
3>SDL_windowsmessagebox.c
3>SDL_windowsmodes.c
3>SDL_windowsmouse.c
3>SDL_windowsopengl.c
3>SDL_windowsopengles.c
3>SDL_windowsshape.c
3>SDL_windowsvideo.c
3>SDL_windowsvulkan.c
3>SDL_windowswindow.c
3>SDL_syscond.c
3>SDL_syscond_srw.c
3>Generating Code...
3>Compiling...
3>SDL_sysmutex.c
3>SDL_syssem.c
3>SDL_systhread.c
3>SDL_systls.c
3>SDL_windowssensor.c
3>SDL_syspower.c
3>SDL_syslocale.c
3>SDL_sysfilesystem.c
3>SDL_systimer.c
3>SDL_sysloadso.c
3>SDL_hidapi_gamecube.c
3>SDL_hidapi_ps4.c
3>SDL_hidapi_ps5.c
3>SDL_hidapi_rumble.c
3>SDL_hidapi_stadia.c
3>SDL_hidapi_steam.c
3>SDL_hidapi_switch.c
3>SDL_hidapi_xbox360.c
3>SDL_hidapi_xbox360w.c
3>SDL_hidapi_xboxone.c
3>Generating Code...
3>Compiling...
3>SDL_hidapijoystick.c
3>hid.c
3>SDL_dinputjoystick.c
3>SDL_mmjoystick.c
3>SDL_rawinputjoystick.c
3>SDL_windows_gaming_input.c
3>SDL_windowsjoystick.c
3>SDL_xinputjoystick.c
3>SDL_dinputhaptic.c
3>SDL_windowshaptic.c
3>SDL_xinputhaptic.c
3>Generating Code...
3>SDL2-static.vcxproj -> E:\PERSON\code\Player\third_lib\SDL\out\Release\SDL2-static.lib
3>Done building project "SDL2-static.vcxproj".
5>------ Build started: Project: SDL2_test_resoureces, Configuration: Release x64 ------
5>Building Custom Rule E:/PERSON/code/Player/third_lib/SDL/test/CMakeLists.txt
5>resources_dummy.c
5>SDL2-static.lib(SDL_stdlib.obj) : error LNK2005: memset already defined in vcruntime.lib(VCRUNTIME140.dll)
5>E:\PERSON\code\Player\third_lib\SDL\out\test\Release\SDL2_test_resoureces.exe : fatal error LNK1169: one or more multiply defined symbols found
5>Done building project "SDL2_test_resoureces.vcxproj" -- FAILED.
6>------ Build started: Project: testyuv, Configuration: Release x64 ------
6>Building Custom Rule E:/PERSON/code/Player/third_lib/SDL/test/CMakeLists.txt
6>testyuv.c
6>testyuv_cvt.c
6>Generating Code...
6>testyuv.vcxproj -> E:\PERSON\code\Player\third_lib\SDL\out\test\Release\testyuv.exe
========== Build: 5 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

step:

  1. cmake-gui configure
  2. open SDL2.sln
  3. build testyuv release
okuoku commented 3 years ago

Perhaps duplicate of #3662 , you can enable LIBC option as workaround. (For both GCC and MSVC,) there's no straightforward way to disable specific optimization that can insert memset etc.

IMHO, static library build should not include its own memset and should defer these to linked executables.

ab503044120 commented 3 years ago

Perhaps duplicate of #3662 , you can enable LIBC option as workaround. (For both GCC and MSVC,) there's no straightforward way to disable specific optimization that can insert memset etc.

IMHO, static library build should not include its own memset and should defer these to linked executables.

the error only occur on build release ,debug build can work well

okuoku commented 3 years ago

the error only occur on build release ,debug build can work well

Results can be inconsistent between optimization levels because static-linking do not guarantee pulling entire .objs in the library and optimization might add/remove function calls.

Re.this particular case, difference comes from MSVCRT(D).LIB.

oku@stripe /cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/lib/x64
$ llvm-nm msvcrt.lib | grep memset
         U memset
00000010 D __memset_nt_iters

oku@stripe /cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/lib/x64
$ llvm-nm msvcrtd.lib | grep memset
00000010 D __memset_nt_iters

Only release version of the runtime library uses memset function and it ultimately pulls that symbol.

ab503044120 commented 3 years ago

the error only occur on build release ,debug build can work well

Results can be inconsistent between optimization levels because static-linking do not guarantee pulling entire .objs in the library and optimization might add/remove function calls.

Re.this particular case, difference comes from MSVCRT(D).LIB.

oku@stripe /cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/lib/x64
$ llvm-nm msvcrt.lib | grep memset
         U memset
00000010 D __memset_nt_iters

oku@stripe /cygdrive/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/lib/x64
$ llvm-nm msvcrtd.lib | grep memset
00000010 D __memset_nt_iters

Only release version of the runtime library uses memset function and it ultimately pulls that symbol.

Thanks for your answer