user2535583
user2535583

Reputation:

SDL2 won't link properly

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".

Upvotes: 2

Views: 18167

Answers (3)

Rocky51
Rocky51

Reputation: 61

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.

Upvotes: 6

zeroc8
zeroc8

Reputation: 863

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)

Upvotes: 6

1ace
1ace

Reputation: 5288

Are you sure you have your libraries in you path ?

Try adding -LC:/whatever/ with the folder that actually contains you libSDL2.a and other *.a to your compiler's arguments.

Upvotes: 0

Related Questions