8

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.

enter image description here

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

3
  • 1
    glfw3 probably made the switch from Carbon (C) to Cocoa (Objective C) for its render context / window management interface. With each version of OS X, less and less core OS functionality is exposed through the Carbon interface and it gets worse if you are writing a 64-bit Carbon-based application. Try adding the Cocoa framework to your build configuration. Commented Aug 22, 2013 at 22:19
  • Did you solve the problem somehow? Commented Mar 16, 2019 at 18:04
  • @FrancescoBoi I had to link to the IOKit, CoreVideo and Cocoa frameworks. See the answers to this question. Commented Mar 16, 2019 at 22:29

2 Answers 2

30

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks. Just for reference, I'll post the command line that just did the trick on my system: gcc -Iglfw3/include/ -Lglfw3/lib/ -lglfw3 -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo main.c.
In my case, I only needed -l glfw3 and that solved it.
In keys if someone is interesting of using GLFW with Swift 3
I added everything suggested except OpenGL (since I am building w Vulkan) and it worked.
13

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.

3 Comments

Hey, thanks for your answer, that did the trick. Additionally to the Cocoa framework, the IOKit framework was also required though.
I also just had this issue and in addition to the Cocoa and IOKit I also had to add the CoreVideo kit and then it was working for me.
@TrevorPeyton: Ah, I see. When I originally wrote this answer, it was to explain only the unresolved symbols in the original question. It appears there are more dependencies introduced with GLFW3 than I originally thought.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.