2013-08-18 102 views
3

我剛開始使用SDL2(在Ubuntu 13.04 x64上),一切都很順利,直到我嘗試使用SDL_image。SDL2 - 未定義的引用 - Ubuntu

我加了這段代碼,加載圖片:

SDL_Texture* LoadImage(std::string file) 
{ 
    SDL_Texture* tex = NULL; 
    tex = IMG_LoadTexture(ren, file.c_str()); 
    if (tex == NULL) 
     throw std::runtime_error("Failed to load image: " + file + IMG_GetError()); 
    return tex; 
} 

我-lSDL2和-lSDL2_image鏈接,和我得到這個未定義的引用:

g++ -o "SDL" ./src/main.o -lSDL2 -lSDL2_image 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_malloc" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_memcmp" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_strncasecmp" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_memset" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_free" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_memcpy" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_sscanf" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_isspace" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_realloc" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_strcmp" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_strncmp" 
/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/libSDL2_image.so: riferimento non definito a "SDL_snprintf" 
collect2: error: ld returned 1 exit status 

我在做什麼錯??

+0

以防萬一,這是不是可以爲[ubuntu.se]一個問題? – brasofilo

+0

我實際上不確定問題是否與Ubuntu相關,或者如果我沒有正確鏈接,或者類似的東西。 – Sylar

+0

我也不是,這不是我的工作領域。查看他們的[幫助中心](http://askubuntu.com/help)和/或研究網站。 – brasofilo

回答

1

你下載並編譯/安裝了庫嗎? 試試這個:

sudo apt-get install libsdl-dev 

之後,你可以編譯和對SDL鏈接:

gcc `pkg-config --libs --cflags sdl` <sourcefile.c> 
+0

感謝您的答案! ...我編譯了庫... libsdl-dev已經安裝好了,它會安裝1.2版本 – Sylar

相關問題