这可能看起来像一个'noob'问题:我已经下载了适用于Mac的SFML-1.6,并且已将框架放入my / Library / Frameworks文件夹中。在尝试编译示例SFML应用程序之后,我几乎每次调用SFML都会遇到链接器错误。我不确定我错过了什么?我对OSX和Frameworks没有太多经验,所以也许我需要通过其他方法链接到库?
输出,如果有帮助:
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)
答案 0 :(得分: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构建文档中并不是很明显,但你确实需要两者。
答案 1 :(得分:2)
似乎您的问题也可以从OS X上经验丰富的开发人员那里得到解答,但由于这也是与SFML相关的问题,我建议您与开发人员(或至少他移植整个事情)联系。 OS X的SFML:hirua。 (或者他也在Stackoverflow吗?)
此外,还有instruction用于在论坛中构建(和使用)SFML 2.0库。也许它对你的1.6版本也有帮助。
(我想补充一下这个评论,但似乎我的名声不是那么好(还))