系统相关
首页 > 系统相关> > c-在使用SDL 2和-static进行编译时,是否收到对各种Windows库的未定义引用?

c-在使用SDL 2和-static进行编译时,是否收到对各种Windows库的未定义引用?

作者:互联网

我正在对SDL2中的Wolfenstein 3D引擎进行修改(使用Wolf4SDL作为基础),但遇到了一个问题-在链接器选项中使用-static时,我得到了各种各样的未定义引用.这是我的构建日志,以显示我的意思:

-------------- Build: Debug in Lazarus (compiler: GNU GCC Compiler)---------------
i686-w64-mingw32-g++.exe -LC:\SDL2\lib -o Lazarus.exe .objs\alu_cache.o .objs\alu_dbg_mem.o .objs\alu_gfx.o .objs\alu_hud.o .objs\alu_in.o .objs\alu_me_core.o .objs\alu_me_gui.o .objs\alu_me_symbols.o .objs\alu_me_textinput.o .objs\alu_me_tools.o .objs\alu_me_windows.o .objs\alu_menu.o .objs\alu_pak.o .objs\alu_particles.o .objs\asmcomp.o .objs\id_us_1.o .objs\vieasm.o .objs\wl_act1.o .objs\wl_act2.o .objs\wl_agent.o .objs\wl_debug.o .objs\wl_dir3dspr.o .objs\wl_draw.o .objs\wl_floorceiling.o .objs\wl_game.o .objs\wl_inter.o .objs\wl_main.o .objs\wl_play.o .objs\wl_state.o .objs\wl_text.o  -static -pg -lgmon  -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -mwindows 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime@0' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks_REAL': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:159: undefined reference to `_imp__timeGetTime@0' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime@0' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_GetTicks_REAL': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:159: undefined reference to `_imp__timeGetTime@0' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:58: undefined reference to `_imp__timeBeginPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `SDL_TicksInit': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:106: undefined reference to `_imp__timeGetTime@0' 
C:\SDL2\lib\libSDL2.a(SDL_systimer.o): In function `timeSetPeriod': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/timer/windows/SDL_systimer.c:52: undefined reference to `_imp__timeEndPeriod@4' 
C:\SDL2\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoInitialize': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c:68: undefined reference to `_imp__CoInitializeEx@8' 
C:\SDL2\lib\libSDL2.a(SDL_windows.o): In function `WIN_CoUninitialize': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/core/windows/SDL_windows.c:87: undefined reference to `_imp__CoUninitialize@0' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_SetupAPI': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:596: undefined reference to `ImmGetIMEFileNameA@12' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:609: undefined reference to `ImmGetContext@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:612: undefined reference to `ImmReleaseContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:530: undefined reference to `ImmGetIMEFileNameA@12' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:545: undefined reference to `GetFileVersionInfoSizeA@8' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:549: undefined reference to `GetFileVersionInfoA@16' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:550: undefined reference to `VerQueryValueA@16' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_GetCandidateList': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:966: undefined reference to `_imp__SysFreeString@4' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:666: undefined reference to `ImmNotifyIME@16' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:670: undefined reference to `ImmNotifyIME@16' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:671: undefined reference to `ImmReleaseContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Disable': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:344: undefined reference to `ImmAssociateContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:668: undefined reference to `ImmSetCompositionStringW@24' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:666: undefined reference to `ImmNotifyIME@16' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:670: undefined reference to `ImmNotifyIME@16' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:671: undefined reference to `ImmReleaseContext@8' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:668: undefined reference to `ImmSetCompositionStringW@24' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_BeginUIElement@12': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1033: undefined reference to `_imp__SysFreeString@4' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UIElementSink_UpdateUIElement@8': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1060: undefined reference to `_imp__SysFreeString@4' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Init': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:289: undefined reference to `_imp__CoCreateInstance@20' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:303: undefined reference to `ImmGetContext@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:304: undefined reference to `ImmReleaseContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `UILess_SetupSinks': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:1174: undefined reference to `_imp__CoCreateInstance@20' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:530: undefined reference to `ImmGetIMEFileNameA@12' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:545: undefined reference to `GetFileVersionInfoSizeA@8' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:549: undefined reference to `GetFileVersionInfoA@16' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetReadingString': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:402: undefined reference to `ImmGetContext@4' 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:477: undefined reference to `ImmReleaseContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_GetId': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:550: undefined reference to `VerQueryValueA@16' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Quit': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:358: undefined reference to `ImmAssociateContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_Enable': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:329: undefined reference to `ImmAssociateContext@8' 
C:\SDL2\lib\libSDL2.a(SDL_windowskeyboard.o): In function `IME_ClearComposition': 
/Users/slouken/release/SDL/SDL2-2.0.3-source/foo-x86/../src/video/windows/SDL_windowskeyboard.c:662: undefined reference to `ImmGetContext@4' 
Process terminated with status 1 (0 minute(s), 0 second(s)) 
50 error(s), 0 warning(s) (0 minute(s), 0 second(s))

链接普通的Wolf4SDL mod(使用SDL 1.2)时,不会发生这种情况;如果我不使用-static,它将正确链接,但是如果没有其他各种DLL(即libgcc_s_dw2-1.dll和喜欢).虽然我可以更改PATH以包括我的MinGW目录,但是在发布该目录时,我不能指望每个人都安装MinGW,并且我希望将通过我的mod分发的DLL的数量保持在最低限度,我已经在使用SDL_mixer和SDL_image,它们已经带有大量的DLL.有人对此有解决方案吗?

解决方法:

好的,解决了这个问题-我需要链接各种Windows库,即Ole32,Oleaut32,Imm32,Winmm和Version.不知道为什么SDL 1不是这种情况.迁移指南中也没有提到它,所以我不确定差异的来源.

标签:sdl-2,c,sdl
来源: https://codeday.me/bug/20191011/1896556.html