【问题标题】:Linker error on GLFW when trying to compile GLFW on Mac尝试在 Mac 上编译 GLFW 时出现 GLFW 上的链接器错误
【发布时间】:2012-10-09 14:37:53
【问题描述】:

我正在尝试在我的 Mac 上通过 xcode 使用 glfw 2.7.5,但出现以下错误:

Undefined symbols for architecture i386:
  "_glfwGetKey", referenced from:
      Game::run() in Game.o
      RedScene::update(float, bool) in main.o
  "_glfwGetWindowParam", referenced from:
      Game::run() in Game.o
  "_glfwInit", referenced from:
      Window::Window() in Window.o
  "_glfwOpenWindow", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwOpenWindowHint", referenced from:
      Window::Window() in Window.o
  "_glfwPollEvents", referenced from:
      Game::run() in Game.o
  "_glfwSetKeyCallback", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwSetMouseButtonCallback", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwSetMousePosCallback", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwSetMouseWheelCallback", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwSetWindowTitle", referenced from:
      Window::setCaption(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in Window.o
  "_glfwSwapBuffers", referenced from:
      RedScene::update(float, bool) in main.o
  "_glfwSwapInterval", referenced from:
      createWindow(int, int, int, int, int, int, int, int) in Window.o
  "_glfwTerminate", referenced from:
      Window::~Window() in Window.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

我已经阅读了这个Problems using GLFW and XCode : won't compile 和互联网上的其他几个链接,但我找不到解决方案。

我在链接器标志中设置了 Cocoa 框架、OpenGL 框架和 libglfw.a(我使用“sudo make cocoa-install”编译),我设置了 -lgflw 并且我正在为 32 位英特尔构建.起初我是为 64 位构建的,但我认为 GLFW 在 Mac 上还不支持它(我遇到了操纵杆文件错误),当我为 32 位编译时错误发生了变化,它找不到我的功能正在使用。知道我能做些什么来解决这个问题吗?

【问题讨论】:

  • 当您构建 libglfw.a 时,您是为 32 位还是 64 位构建它?使用 file libglfw.a 检查它是否为 32 位。
  • 它是 64 位的(我不得不使用“lipo -info”代替“文件”。)有没有办法从 64 位机器变成 32 位?
  • 您需要查看 README、文档、makefile 或 libglfw 的任何内容,以了解如何构建 32 位版本。或者,您可以将您的应用程序构建为 64 位而不是 32 位。
  • GLFW 还不支持 64 位 mac。我会考虑构建 32 位版本。如果你回答我会接受它,谢谢你的帮助:)
  • 没问题 - 我在下面汇总了一个答案,其中我添加了一些进一步的建议。

标签: c++ xcode cocoa linker glfw


【解决方案1】:

您很可能已经为 64 位构建了 libglfw.a,因此当您尝试在 32 位应用程序中使用它时会出现链接错误。您可以为 32 位重建 libglfw.a(或作为“胖”32 位和 64 位库),或者您可以将您的应用程序构建为 64 位。

请注意,在最近的 Mac OS X 和 Xcode 版本中,gcc 默认构建 64 位代码,因此您需要在命令行中指定 -m32 才能获取 32 位代码。在实践中如何执行此操作取决于 libglfw.a 的生成文件 - 很可能有一个 ARCH 或您可以在命令行上指定的其他符号以强制执行 32 位构建。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 2018-06-29
    • 2014-03-27
    • 2020-10-18
    相关资源
    最近更新 更多