简体   繁体   中英

Linker error on GLFW when trying to compile GLFW on Mac

I'm trying to use glfw 2.7.5 on my mac with xcode but I'm getting the following errors:

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) 

I've read this Problems using GLFW and XCode : won't compile and several other links on the internet but I can't find a solution.

I've set the Cocoa framework, the OpenGL framework and libglfw.a (which I compiled using "sudo make cocoa-install"), in the linker flags I set -lgflw and I'm building for 32-bit Intel. At first I was building for a 64-bit but I think GLFW doesn't support that on Mac yet (I was getting joystick file errors), the error changes when I compile for 32-bit and it can't find the functions I'm using. Any idea what I could do to fix this?

Most likely you have built libglfw.a for 64 bit and so you get link errors when you try to use it in a 32 bit app. You can either rebuild libglfw.a for 32 bit (or as a "fat" 32 bit and 64 bit library), or you could just build your app as 64 bit.

Note that in recent version of Mac OS X and Xcode, gcc builds 64 bit code by default, so you need to specify -m32 on the command line to get 32 bit code. How you do this in practice depends on the makefile for libglfw.a - there may well be an ARCH or other symbol that you can specify on the command line to force a 32 bit build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM