2014-10-05 68 views
0

我正在嘗試在CodeBlocks中設置SDL 2.0.3將近兩天,至今沒有運氣。

我正在使用最新版本的Codeblocks,MinGW和SDL。

我想我已經適當地包括從聯的所有SDL文件LIB包括目錄切換到代碼塊由代碼塊使用Settings/Compiler/Search Directories

我還添加以下行到設置/編譯器/連接設置/其他連接器選項:未定義對SDL功能的引用

-lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer 


我已經加入SDL2.dll項目目錄。

我相信我正在使用正確的SDL文件。我有64個系統,我正在使用x86_64-w64-mingw32目錄中的文件。根據Web上的幾個教程,64系統應該是正確的。

( 當您下載SDL開發庫有版本的32位和64位系統,以便有兩個目錄:x86_64的-W64-的mingw32的i686-W64-的mingw32他們的名字是在我看來相當誤導)

我有這個簡單的測試代碼:

#include <SDL.h> 

int main(int argc, char* argv[]) { 

    // Start SDL2 
    SDL_Init(SDL_INIT_EVERYTHING); 

    // Create a Window in the middle of the screen 
    SDL_Window *window = 0; 

    window = SDL_CreateWindow("Hello World!", 
           SDL_WINDOWPOS_CENTERED, 
           SDL_WINDOWPOS_CENTERED, 
           640, 480, 
           SDL_WINDOW_SHOWN); 

    // Delay so that we can see the window appear 
    SDL_Delay(2000); 

    // Cleanup and Quit 
    SDL_DestroyWindow(window); 
    SDL_Quit(); 

    return 0; 
} <br> 

我說編譯如下:

mingw32-g++.exe -LC:\SDL\SDL2_2.0.3\lib -LC:\SDL\SDL2_image_2.0.0\lib -LC:\SDL\SDL2_mixer_2.0.0\lib -o bin\Debug\Snake.exe obj\Debug\main.o -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer 
obj\Debug\main.o: In function `SDL_main': 
D:/CodeBlocks/Snake/main.cpp:6: undefined reference to `SDL_Init' 
D:/CodeBlocks/Snake/main.cpp:15: undefined reference to `SDL_CreateWindow' 
D:/CodeBlocks/Snake/main.cpp:18: undefined reference to `SDL_Delay' 
D:/CodeBlocks/Snake/main.cpp:21: undefined reference to `SDL_DestroyWindow' 
D:/CodeBlocks/Snake/main.cpp:22: undefined reference to `SDL_Quit' 
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `[email protected]' 
collect2.exe: error: ld returned 1 exit status 



我按照這個教程:https://www.youtube.com/watch?v=wWGtuc5uqF4
事情已經改變sligthly,因爲當你下載SDL開發庫,並對其進行解壓縮。它看起來不同,但我相信我做到了至少partialy正確的,因爲編譯器可以在發現<SDL.h>

我知道有幾個相同或相似問題,但它們都沒有公認的答案。

我會感謝每一個幫助。

+1

嘗試64位編譯'-m64'。 – user1810087 2014-10-05 10:55:56

+0

這沒有幫助 – Rokusjar 2014-10-05 12:53:42

回答

0

我意識到,那tutorial之前是爲32位版本做我所提到的,所以我嘗試使用32位版本,現在一切工作。

除了你需要獲得SDL_platform.h文件的固定版本並替換舊版本。這是SDL 2.0.3版中的一個錯誤,應根據我在互聯網上發現的更新版本進行修復。

如果你不這樣做,你會得到彙編錯誤說一些關於winapifamily.h