2012-10-09 35 views
0

我想在我的Mac和Xcode使用GLFW 2.7.5,但我发现了以下错误:链接错误当试图编译GLFW在Mac

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位,它无法找到函数I正在使用。任何想法我可以做什么来解决这个问题?

+0

当你建立'libglfw.a'你建立它的32位或64位?使用'file libglfw.a'来检查它是否是32位。 –

+0

这是64位(我不得不使用“文件”的“lipo -info”实例)。有没有办法将它从64位机器上升到32位? –

+0

您需要阅读README,docs,makefile或任何libglfw以了解如何构建32位版本。另外,你可以建立你的应用程序为64位而不是32位。 –

回答

1

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

请注意,在最新版本的Mac OS X和Xcode中,默认情况下,gcc会构建64位代码,因此您需要在命令行上指定-m32以获取32位代码。在实践中如何实现这一点取决于libglfw.a的makefile - 可能有一个ARCH或其他符号,您可以在命令行上指定该符号来强制构建32位。