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
. 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). nm
finds all the functions, so the static library files are perfectly fine. By the way, I don't use SDL_main
, therefore it'sn't on the list.
So, why is ld
not finding the SDL functions?
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:
-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