2011-12-17 82 views
5

這可能看起來像一個'noob'問題:我已經爲Mac下載了SFML-1.6,並且已將框架放入我的/ Library/Frameworks文件夾中。在嘗試編譯示例SFML應用程序後,我幾乎每次打電話給SFML都會收到鏈接程序錯誤。我不確定我錯過了什麼?我沒有太多的OSX和框架經驗,所以也許我需要通過其他方法鏈接到庫?OS X上的鏈接錯誤

輸出,如果它可以幫助:

Undefined symbols for architecture x86_64: 
    "sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::RenderWindow::RenderWindow(sf::VideoMode, std::string const&, unsigned long, sf::WindowSettings const&)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::RenderTarget::PreserveOpenGLStates(bool)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::Image()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::LoadFromFile(std::string const&)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Sprite::Sprite(sf::Image const&, sf::Vector2<float> const&, sf::Vector2<float> const&, float, sf::Color const&)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::GetWidth() const", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::GetHeight() const", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::GetPixelsPtr() const", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Image::~Image()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Clock::Clock()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Window::IsOpened() const", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Window::GetEvent(sf::Event&)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Window::Close()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Clock::GetElapsedTime() const", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Unicode::Text::Text(char const*)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Font::GetDefaultFont()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::String::String(sf::Unicode::Text const&, sf::Font const&, float)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Drawable::SetPosition(float, float)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Drawable::SetColor(sf::Color const&)", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::Window::Display()", referenced from: 
     osx_init::init() in osx_init.o 
    "sf::RenderWindow::~RenderWindow()", referenced from: 
     osx_init::init() in osx_init.o 
    "vtable for sf::Sprite", referenced from: 
     sf::Sprite::~Sprite() in osx_init.o 
    "sf::Drawable::~Drawable()", referenced from: 
     sf::Sprite::~Sprite() in osx_init.o 
     sf::String::~String() in osx_init.o 
    "vtable for sf::String", referenced from: 
     sf::String::~String() in osx_init.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

回答

2

看來你的問題也可以從OS X一個有經驗的開發人員回答,但因爲它是一個SFML相關的問題也一樣,我建議你取得聯繫與開發人員(或至少他移植了全部)SFML for OS X:hirua。 (或者他也在Stackoverflow上?)

此外,還有一個instruction用於在論壇中構建(並使用)SFML 2.0庫。也許這對你的1.6版本也有幫助。

(我想補充這只是一個評論,但似乎我的名聲不是很大(但))

6

你需要兩個標誌添加到鏈接器選項:

-framework SFML 

這告訴鏈接器使用的框架/Library/Frameworks/SFML.framework

此外,你必須包括-lsfml-whatever每個庫你使用:

-lsfml-system 
-lsfml-window 
-lsfml-graphics 
-lsfml-audio 
-lsfml-network 

所以,一個完整的鏈接線可能看起來像:

g++ -framework SFML -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system 

從Mac OSX SFML建立文檔這不是很明顯,但你需要兩者。

+0

不,'-framework SFML'沒用。這是一個只包含頭文件的虛擬框架。如果你安裝了dylib,你可能還在'/ usr/local /'中安裝了頭文件,所以你不需要這個額外的框架。 – Hiura 2014-05-28 17:22:10