由于SFML框架,OS X上的链接器错误

krs*_*ynx 5 c++ linker sfml

这可能看起来像一个'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)
Run Code Online (Sandbox Code Playgroud)

nat*_*are 6

您需要在链接器选项中添加两个标志:

-framework SFML
Run Code Online (Sandbox Code Playgroud)

这告诉链接器使用框架 /Library/Frameworks/SFML.framework

此外,您必须包括-lsfml-whatever您正在使用的每个库:

-lsfml-system
-lsfml-window
-lsfml-graphics
-lsfml-audio
-lsfml-network
Run Code Online (Sandbox Code Playgroud)

因此,完整的链接器行可能如下所示:

g++ -framework SFML -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
Run Code Online (Sandbox Code Playgroud)

这在Mac OSX SFML构建文档中并不是很明显,但您确实需要两者.


Luk*_*kas 2

看来你的问题也可以从 OS X 上经验丰富的开发人员那里得到解答,但由于这也是一个 SFML 相关问题,我建议你与 SFML for OS 的开发人员联系(或者至少他移植了整个东西) X:希鲁阿。(或者他也在 Stackoverflow 上吗?)

此外,论坛中还有关于构建(和使用)SFML 2.0 库的说明。也许它对你的 1.6 版本也有帮助。

(我想添加这只是一条评论,但似乎我的声誉还不是很好)