我正在使用 Code::Blocks,这是我的代码:
#include "SDL2/SDL.h"
int main(int argc, char* args[]) {
SDL_Init( SDL_INIT_EVERYTHING );
SDL_Quit();
return 0;
}
我正在构建:
mingw32-g++.exe -o C:\..\main.exe C:\..\main.o -lmingw32 -lSDL2main -lSDL2
然后得到:
undefined reference to "SDL_Init"
undefined reference to "SDL_Quit"
我很确定链接器找到了库,因为如果我将它们更改为随机的东西,它会提示“找不到任何东西”。
最佳答案
有点晚了,但我刚刚在 Linux 上遇到了类似的问题。
这会导致链接器错误:
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'
这个有效:
g++ sdl2test.cpp $(pkg-config --cflags --libs sdl2)
关于c++ - SDL2 无法正确链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17386032/