尝试在Mac上编译GLFW时GLFW上的链接器错误

时间:2012-10-09 14:37:54

标签: c++ xcode cocoa linker glfw

我正在尝试使用xcode在我的mac上使用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位Intel构建。起初我正在构建一个64位,但我认为GLFW不支持Mac上的那个(我得到操纵杆文件错误),当我编译为32位时它的错误发生了变化,它无法找到函数我'正在使用。知道我能做些什么来解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

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

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