xcode 使用 GLFW3 编译,链接器错误“未定义引用”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18391487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:43:24  来源:igfitidea点击:

Compiling with GLFW3, linker errors 'undefined reference'

c++xcodemacosopenglglfw

提问by Appleshell

Having a minimal example using GLFW3:

有一个最小的例子使用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.frameworkand libglfw3.aare both linked.

OpenGL.framework并且libglfw3.a两者都有联系。

enter image description here

在此处输入图片说明

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

这是什么原因?glfw2之前编译应用程序就像一个魅力。

回答by Andon M. Coleman

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

在 Mac OS X 中,glfw3 使用 Cocoa (NSGL) 进行 OpenGL 上下文管理。glfw2 使用 Carbon(CGL/AGL,取决于全屏或窗口模式)。

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.

NSGL 更健壮,但它建立在 Objective C 框架 (Cocoa) 之上。为了让您的软件与 glfw3 一起正常工作,您应该包含 Cocoa 框架。