我试图建立一个基于MinGW并使用SDL的C++项目。当我尝试编译我的程序时,g ++会为我使用的每个SDL函数指定undefined reference to 'SDL_Function'
。SDL2未定义的函数引用
库/ SDL2:
#include "SDL.h"
int main(int argc, char *argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *window = SDL_CreateWindow(
"Hello World",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
640, 480, 0
);
SDL_Delay(3000);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
我用耙简化:从SDL网站
源/ Main.cpp的SDL2-devel的-2.0.0-mingw.tar.gz内容构建过程中一点点,它产生的是条命令:
g++ -Wall -ILib/SDL2/i686-w64-mingw32/include/SDL2 -Dmain=SDL_main -LLib/SDL2/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows Source/Main.cpp -o Build/sdltest.exe
而且这里是G ++说:
Main.cpp:(.text+0xe): undefined reference to `SDL_Init'`
Main.cpp:(.text+0x42): undefined reference to `SDL_CreateWindow'`
Main.cpp:(.text+0x51): undefined reference to `SDL_Delay'`
Main.cpp:(.text+0x5c): undefined reference to `SDL_DestroyWindow'`
Main.cpp:(.text+0x61): undefined reference to `SDL_Quit'`
ld.exe: bad reloc address 0x20 in section `.eh_frame'`
ld.exe: final link failed: Invalid operation`
collect2.exe: error: ld returned 1 exit status`
它看起来像一个普通初学者的问题,但我想我通过了所有的故障排除要点:
- 主要功能有
int argc, char *argv[]
- 我使用所有的SDL-配置(-Dmain = SDL_main标志 - lmingw32 -lSDL2main -lSDL2 -mwindows)
- 我试图使用32位的MinGW
- 时使用 '的i686-W64-mingw32的' 版本应该所有指定的路径似乎正确
任何线索怎么回事?
如何确保链接器能够找到定义? –
感谢您的回复。我该怎么做? – VCake
我记得绊倒了一个类似于这个奇怪的问题,但我不记得确切的细节。尝试改变输入参数的顺序,例如g ++ -o sdltext.exe $(sdlconfig --libs) – zeroc8