2013-02-21 39 views
3

我只是想將我的程序源移到我的新計算機上並按照SFMLCoder的最新說明自行安裝Codeblocks 12.11和編譯SFML 2。一切正常。當我嘗試編譯此:鏈接到SFML 2拋出對sf :: Window構造函數的未定義引用

#include <iostream> 

using namespace std; 

#include <SFML/Window.hpp> 

int main() 
{ 
    cout << "Hello world!" << endl; 

    sf::Window w(sf::VideoMode(800, 600), "test"); 

    return 0; 
} 

我想靜(與在Buildoptions用C定義SFML_STATIC :: B),調試庫的動態和兩者。但總是在它鏈接文件後它說: main.cpp|11|undefined reference to sf::Window::Window(sf::VideoMode, std::string const&, unsigned int, sf::ContextSettings const&) 或當使用動態庫 main.cpp|11|undefined reference to _imp___ZN2sf6WindowC1ENS_9VideoModeERKSsjRKNS_15ContextSettingsE 這顯然是相當於靜態鏈接錯誤。

編輯: 我在官方SFML-forum中發現了一個線程,問題完全相同:如果我理解正確,我會發布解決方案。

+0

你運行什麼命令來編譯? – Xymostech 2013-02-21 15:10:03

+0

@Xymostech我通過CMake和C :: B編譯SFML 2,通過執行這個'mingw32-g ++。exe -Wall -fexceptions -g -IC:\ Users \ User \ CBP \ Test \ -c編譯main.cpp C: \ Users \ User \ CBP \ Test \ main.cpp -o obj \ Debug \ main.o '和鏈接到'mingw32-g ++ .exe -o。\ Publish \ Test.exe obj \ Debug \ main.o .. \ .. \ .. \ .. \ sfml2 \ lib \ libsfml-graphics-da .. \ .. \ .. \ .. \ sfml2 \ lib \ libsfml-system-da .. \ .. \ .. \。 \ sfml2 \ lib \ libsfml-window-da collect2.exe:錯誤:ld返回1退出狀態# – JoshuaBehrens 2013-02-21 15:50:44

+0

嗯...... [this](http://stackoverflow.com/questions/11996792/making-a-sfml2 -applcation-with-clang-libc-and-c11-undefined-reference-to-s)聽起來和你的問題非常相似,並且他們遇到了問題,因爲sfml和他們的程序正在使用不同的設置進行編譯...... cmake是否使用mingw32-g ++來編譯它? (您可以通過使用'make VERBOSE = 1'重新運行make來檢查) – Xymostech 2013-02-21 15:59:43

回答

0

我將自己加入到this discussion中,它揭示我必須從github下載版本,並且必須包含SFML/Window.hpp。它從現在開始工作。希望這個答案也能幫助其他人。

相關問題