简体   繁体   English

带有mingw-w64的SDL2-链接器找到libSDL2.a但抛出“未定义的引用”错误

[英]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.

相关问题 使用带有mingw-w64的Allegro 5的未定义参考 - Undefined reference using Allegro 5 with mingw-w64 mingw-w64 中的编译器错误:“未定义对 __getreent 的引用。” - Compiler error in mingw-w64: 'undefined reference to `__getreent.' MinGW-w64 OpenGL链接器错误 - MinGW-w64 OpenGL linker error 库中的MinGW-w64编译错误 - MinGW-w64 compilation errors in libraries SDL2未定义对MinGW几个功能的引用 - SDL2 undefined reference to several functions with MinGW 使用协议缓冲区的程序无法用MinGW-w64编译:“对google :: protobuf ::…的未定义引用” - Program with protocol-buffers don't compile with MinGW-w64: “undefined reference to google::protobuf:: …” MinGW-w64 gcc上对boost :: random :: random_device构造函数和析构函数的未定义引用 - Undefined reference to boost::random::random_device constructor and destructor on MinGW-w64 gcc 未定义的参考链接yaml-cpp程序与mingw-w64 + cmake - undefined reference linking yaml-cpp program with mingw-w64 + cmake 将 Winsock2 添加到我的 MinGW-w64 C/C++ 会导致:未定义对“InitializeConditionVariable”的引用 - Adding Winsock2 to my MinGW-w64 C/C++ causes: undefined reference to `InitializeConditionVariable' 为什么在使用SDL2时仍然出现“未定义参考”链接器错误? - Why am I still getting 'undefined reference' linker errors when using SDL2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM