带有 mingw-w64 的 SDL2 - 链接器发现 libSDL2.a 但抛出 "undefined reference" 错误
SDL2 with mingw-w64 - linker finds libSDL2.a but throws "undefined reference" errors
尽管 libSDL2.a
根据 -Xlinker --verbose
被链接器识别(并使用),但我使用的每个 SDL 函数都被 [= 报告为 "undefined reference" 15=]。这是我调用的链接器命令行:
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
如您所见,我使用了正确的库版本(x86_64
库,x86_64
编译器)。 nm
找到所有函数,所以静态库文件完全没问题。顺便说一句,我不使用 SDL_main
,因此它不在列表中。
那么,为什么 ld
找不到 SDL 函数?
在 and 之后,我将静态库放在目标文件之后并添加了更多库(以及删除了 -lSDLmain
),库列表变为:
-lSDL2 -lgdi32 -lole32 -loleaut32 -lmingw32 -limm32 -lwinmm -lversion -lSetupAPI
所以最后的命令行是:
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
尽管 libSDL2.a
根据 -Xlinker --verbose
被链接器识别(并使用),但我使用的每个 SDL 函数都被 [= 报告为 "undefined reference" 15=]。这是我调用的链接器命令行:
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
如您所见,我使用了正确的库版本(x86_64
库,x86_64
编译器)。 nm
找到所有函数,所以静态库文件完全没问题。顺便说一句,我不使用 SDL_main
,因此它不在列表中。
那么,为什么 ld
找不到 SDL 函数?
在 -lSDLmain
),库列表变为:
-lSDL2 -lgdi32 -lole32 -loleaut32 -lmingw32 -limm32 -lwinmm -lversion -lSetupAPI
所以最后的命令行是:
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