2012-10-09 36 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位。