[英]SDL2 Undefined references to functions
我正在嘗試建立一個基於MinGW並使用SDL的C ++項目。 當我嘗試編譯我的程序時,g ++對我使用的每個SDL函數說undefined reference to 'SDL_Function'
。
Lib / SDL2:來自SDL網站的SDL2-devel-2.0.0-mingw.tar.gz的內容
來源/ Main.cpp的:
#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;
}
我正在使用Rake來簡化構建過程,它產生的命令是:
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[]
有什么想法發生了什么?
嘗試更改輸入參數的順序:
我之前(在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)
我改變了輸入參數的順序和它的工作,把SDL2main SLD2之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.