SDL2 will not bind correctly

I am using Code :: Blocks, which is my code:

#include "SDL2/SDL.h" int main(int argc, char* args[]) { SDL_Init( SDL_INIT_EVERYTHING ); SDL_Quit(); return 0; } 

I build as:

 mingw32-g++.exe -o C:\..\main.exe C:\..\main.o -lmingw32 -lSDL2main -lSDL2 

And having received this:

 undefined reference to "SDL_Init" undefined reference to "SDL_Quit" 

I am sure that the linker will find the cause of the libs if I change them to something random, which it complains “cannot find anything”.

+2
c ++ linker codeblocks sdl
source share
3 answers

A bit late, but I just stumbled upon a similar problem on Linux.

This leads to 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' 

It works:

 g++ sdl2test.cpp $(pkg-config --cflags --libs sdl2) 
+6
source share

even if this is a Linux problem, I got to this entry via google.

Mayb this can help someone else: I had the same problem with 32-bit Windows XP code blocks: Mingw + SDL2 and I fixed it after I copied the correct SDLFolders (include, lib ...) to the mingw folder . The reason I ended up in this pythall is because the name of the SDL-Rootfolder from the DEV-Pack is a bit confusing. You have the "x86_64-w64-mingw32" -Folder, which is for the 64-bit compiler and the "i686-w64-mingw32", which is for the 32-bit compiler (as is still the case). I messed it up because of the "x86 ..." naming, still don't know why they write it that way.

After overwriting the correct files, it works great for me.

+6
source share

Are you sure you have your libraries in your way?

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

0
source share

All Articles