[英]SDL2 with mingw-w64 - linker finds libSDL2.a but throws “undefined reference” errors
Even though libSDL2.a
is, according to -Xlinker --verbose
, recognized (and is used) by the linker, every single SDL function that I use is reported as "undefined reference" by ld.exe
. 根据
-Xlinker --verbose
,即使libSDL2.a
被链接器识别(并使用),我使用的每个SDL函数也被ld.exe
报告为“未定义引用”。 Here's the linker command line that I invoke: 这是我调用的链接器命令行:
x86_64-w64-mingw32-g++.exe -L./Client/deps/SDL2/x86_64-w64-mingw32/lib -lgdi32 -lSDL2main -lSDL2 ./Client/deps/gl3w/obj/windows/x86_64/release/gl3w.o ./Client/build/output/o/windows/x86_64/dev/GVGLObjects.cpp.o ./Client/build/output/o/windows/x86_64/dev/GVRenderer.cpp.o ./Client/build/output/o/windows/x86_64/dev/GVWorldObjects.cpp.o
./Client/build/output/o/windows/x86_64/dev/main.cpp.o -o ./Client/build/output/exe/windows/x86_64/dev/GemVerse.exe
As you can see, I use the correct library version ( x86_64
libraries, x86_64
compiler). 如您所见,我使用了正确的库版本(
x86_64
库, x86_64
编译器)。 nm
finds all the functions, so the static library files are perfectly fine. nm
找到了所有功能,因此静态库文件非常好。 By the way, I don't use SDL_main
, therefore it'sn't on the list. 顺便说一句,我不使用
SDL_main
,因此它不在列表中。
So, why is ld
not finding the SDL functions? 那么,为什么
ld
没有找到SDL函数?
Following Keltar's comment and HolyBlackCat's comment , I put the static libraries after the object files and added some more libraries (as well as removed -lSDLmain
), the list of libraries becoming: 按照Keltar的评论和HolyBlackCat的评论 ,我将静态库放在目标文件之后,并添加了更多库(以及删除的
-lSDLmain
),库列表变为:
-lSDL2 -lgdi32 -lole32 -loleaut32 -lmingw32 -limm32 -lwinmm -lversion -lSetupAPI
So the final command line is: 所以最后一个命令行是:
PS> 86_64-w64-mingw32-g++.exe -L./Client/deps/SDL2/x86_64-w64-mingw32/lib ./Client/deps/gl3w/obj/windows/x86_64/release/gl3w.o ./Client/build/output/o/windows/x86_64/dev/GVGLObjects.cpp.o ./Client/build/output/o/windows/x86_64/dev/GVRenderer.cpp.o ./Client/build/output/o/windows/x86_64/dev/GVWorldObjects.cpp.o
./Client/build/output/o/windows/x86_64/dev/main.cpp.o -lSDL2 -lgdi32 -lole32 -loleaut32 -lmingw32 -limm32 -lwinmm -lversion -lSetupAPI -o ./Client/build/output/exe/windows/x86_64/dev/GemVerse.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.