Compiling with GLFW3, linker errors 'undefined reference'

妖精的绣舞 提交于 2019-11-29 15:18:23

问题


Having a minimal example using GLFW3:

#include <GLFW/glfw3.h>

int main(int argc, const char * argv[]) {
    glfwInit();
}

...results in a ton of linker errors: (small excerpt)

Undefined symbols for architecture x86_64:
  "_CFArrayAppendValue", referenced from:
      _addJoystickElement in libglfw3.a(cocoa_joystick.m.o)
  "_CFArrayApplyFunction", referenced from:
      __glfwInitJoysticks in libglfw3.a(cocoa_joystick.m.o)
      _addJoystickElement in libglfw3.a(cocoa_joystick.m.o)
  "_CFArrayCreateMutable", referenced from:
      __glfwInitJoysticks in libglfw3.a(cocoa_joystick.m.o)

  ...

  "_objc_msgSend_fixup", referenced from:
  l_objc_msgSend_fixup_count in libglfw3.a(cocoa_monitor.m.o)
  l_objc_msgSend_fixup_objectAtIndex_ in libglfw3.a(cocoa_monitor.m.o)
  l_objc_msgSend_fixup_objectForKey_ in libglfw3.a(cocoa_monitor.m.o)
  l_objc_msgSend_fixup_alloc in libglfw3.a(cocoa_init.m.o)
  l_objc_msgSend_fixup_release in libglfw3.a(cocoa_init.m.o)
  l_objc_msgSend_fixup_alloc in libglfw3.a(nsgl_context.m.o)
  l_objc_msgSend_fixup_release in libglfw3.a(nsgl_context.m.o)
  ...

OpenGL.framework and libglfw3.a are both linked.

What is the reason for this? Compiling a glfw2 application before worked like a charm.


回答1:


In Mac OS X, glfw3 uses Cocoa (NSGL) for its OpenGL context management. glfw2 used Carbon (CGL/AGL, depending on fullscreen or windowed mode).

NSGL is more robust, but it is built upon an Objective C framework (Cocoa). In order for your software to work correctly with glfw3, you should include the Cocoa framework.




回答2:


If you are using the static library version of GLFW, add it and the Cocoa, OpenGL, IOKit and CoreVideo frameworks to the project as dependencies.



来源:https://stackoverflow.com/questions/18391487/compiling-with-glfw3-linker-errors-undefined-reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!