【问题标题】:Linker Errors on OS X due to SFML framework由于 SFML 框架导致 OS X 上的链接器错误
【发布时间】:2012-01-22 17:31:21
【问题描述】:

这似乎是一个相当“菜鸟”的问题:我已经下载了适用于 Mac 的 SFML-1.6,并将框架放入我的 /Library/Frameworks 文件夹。在尝试编译示例 SFML 应用程序后,我几乎每次调用 SFML 都会遇到链接器错误。我不确定我错过了什么?我对 OSX 和框架没有太多经验,所以也许我需要通过其他方法链接到库?

输出,如果有帮助的话:

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)

【问题讨论】:

    标签: c++ linker sfml


    【解决方案1】:

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

    -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 构建文档中并不是很明显,但您确实需要两者。

    【讨论】:

    • 不,-framework SFML 没用。这是一个只包含标题的虚拟框架。如果您安装了 dylibs,您可能还在 /usr/local/ 中安装了标头,因此您不需要这个额外的框架。
    【解决方案2】:

    似乎您的问题也可以从 OS X 上的经验丰富的开发人员那里得到解答,但由于这也是一个与 SFML 相关的问题,我建议您与开发人员联系(或者至少他移植了整个事情)用于 OS X 的 SFML:hirua。 (或者他也在 Stackoverflow 上?)

    此外,论坛中还有一个instruction 用于构建(和使用)SFML 2.0 库。也许它对您的 1.6 版本也有帮助。

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

    【讨论】:

      猜你喜欢
      • 2016-02-04
      • 2017-06-12
      • 1970-01-01
      • 2014-03-27
      • 2014-10-14
      • 2021-02-22
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多