Problems linking against GLFW in OSX
Asked Answered
T

1

3

I'm getting a ton of linker errors (included below) when I run my C++ OpenGL program through the linker. I have no problem compiling OpenGL programs that don't have a dependence on GLFW. I'm not really sure where to go from here, because I've done very little C++/ObjC development on Mac -- any ideas? Thanks!

The command being run is:

g++ -framework Carbon -framework OpenGL -framework GLUT -lglfw -framework AGL -arch i386 display.o voxels.o -o cubile

The error is:

Undefined symbols for architecture i386:
  "_objc_msgSend", referenced from:
      __glfwPlatformOpenWindow in libglfw.a(cocoa_window.o)
      -[GLFWContentView mouseDragged:] in libglfw.a(cocoa_window.o)
      -[GLFWContentView rightMouseDragged:] in libglfw.a(cocoa_window.o)
      -[GLFWContentView otherMouseDragged:] in libglfw.a(cocoa_window.o)
      __glfwPlatformPollEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformWaitEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformRefreshWindowParams in libglfw.a(cocoa_window.o)
      ...
  "_objc_msgSend_stret", referenced from:
      -[GLFWWindowDelegate windowDidResize:] in libglfw.a(cocoa_window.o)
      __glfwPlatformSetWindowPos in libglfw.a(cocoa_window.o)
      -[GLFWContentView mouseMoved:] in libglfw.a(cocoa_window.o)
  "_objc_msgSend_fpret", referenced from:
      -[GLFWContentView mouseMoved:] in libglfw.a(cocoa_window.o)
      -[GLFWContentView scrollWheel:] in libglfw.a(cocoa_window.o)
      __glfwPlatformGetTime in libglfw.a(cocoa_time.o)
      __glfwPlatformSetTime in libglfw.a(cocoa_time.o)
  "_objc_msgSendSuper", referenced from:
      -[GLFWContentView keyDown:] in libglfw.a(cocoa_window.o)
      -[GLFWApplication sendEvent:] in libglfw.a(cocoa_init.o)
  "_NSApp", referenced from:
      __glfwPlatformOpenWindow in libglfw.a(cocoa_window.o)
      __glfwPlatformPollEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformWaitEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformCloseWindow in libglfw.a(cocoa_window.o)
      __glfwPlatformInit in libglfw.a(cocoa_init.o)
      __glfwPlatformOpenWindow in libglfw.a(cocoa_window.o)
      __glfwPlatformPollEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformWaitEvents in libglfw.a(cocoa_window.o)
      __glfwPlatformCloseWindow in libglfw.a(cocoa_window.o)
      __glfwPlatformInit in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSAutoreleasePool", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSString", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSCursor", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSScreen", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSOpenGLContext", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSOpenGLPixelFormat", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSWindow", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSView", referenced from:
      .objc_class_name_GLFWContentView in libglfw.a(cocoa_window.o)
  ".objc_class_name_NSMenuItem", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSMenu", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSBundle", referenced from:
      pointer-to-literal-objc-class-name in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSThread", referenced from:
      .objc_class_name_GLFWThread in libglfw.a(cocoa_init.o)
  ".objc_class_name_NSApplication", referenced from:
      .objc_class_name_GLFWApplication in libglfw.a(cocoa_init.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
Tremble answered 26/12, 2011 at 17:24 Comment(3)
are you building this in Xcode or from the command line or a make file or?Merrell
It's running from a Makefile. I forgot to add the command to the question -- I'll edit to add it now.Tremble
Foundation didn't, but Cocoa did. Thanks for the help!Tremble
T
2

Solved it -- I was linking against Carbon when the newer versions of GLFW use Cocoa. Replacing -framework Carbon with -framework Cocoa solved the problem.

Tremble answered 26/12, 2011 at 18:30 Comment(1)
Would anyone or you happen to know how to add these flags with Cmake?Pinebrook

© 2022 - 2024 — McMap. All rights reserved.