SDL2 won't link properly
Solution 1
A bit late, but I just stumbled over a similar problem on Linux.
This results in linker errors:
g++ $(pkg-config --cflags --libs sdl2) sdl2test.cpp
sdl2test.cpp:(.text+0x11): undefined reference to `SDL_Init'
sdl2test.cpp:(.text+0x20): undefined reference to `SDL_GetError'
sdl2test.cpp:(.text+0x34): undefined reference to `SDL_Quit'
This works:
g++ sdl2test.cpp $(pkg-config --cflags --libs sdl2)
Solution 2
even if this is an Linux Problem, i came throug this post via google.
Mayb it could help someone else: i had the same Problem with Windows XP 32bit Codeblocks: Mingw + SDL2 and i fixed it after i copied the right SDLFolders (include, lib...) to the mingw-folder. The reason why i trapped to this pifall is that the naming of the SDL-Rootfolder, out of the DEV-Pack is a bit confusing. You got a "x86_64-w64-mingw32"-Folder which is for 64bit Compiler and "i686-w64-mingw32" which is for 32bit Compiler (like the moste still are). i messed this up because of the "x86..."naming, still dont know why they are writing it this way.
After overwriting the right files it works fine for me.
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
I'm using Code::Blocks, that's my code:
#include "SDL2/SDL.h" int main(int argc, char* args[]) { SDL_Init( SDL_INIT_EVERYTHING ); SDL_Quit(); return 0; }
I'm building like:
mingw32-g++.exe -o C:\..\main.exe C:\..\main.o -lmingw32 -lSDL2main -lSDL2
And getting that:
undefined reference to "SDL_Init" undefined reference to "SDL_Quit"
I'm pretty sure the linker finds the libs cause if I change them to something random it complains "can't find whatever".