SDL2 won't link properly

扶醉桌前 提交于 2019-12-02 02:37:33

问题


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


回答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)



回答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.




回答3:


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.



来源:https://stackoverflow.com/questions/17386032/sdl2-wont-link-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!