在OSX中的xcode中查找glfw库文件?

时间:2014-11-20 07:39:00

标签: c++ xcode opengl linker glfw

所以我正在尝试使用OpenGL和GLFW构建程序。我遇到的唯一错误是:

Undefined symbols for architecture x86_64:
  "_glewInit", referenced from:
      _main in main.o
  "_glfwCreateWindow", referenced from:
      _main in main.o
  "_glfwGetKey", referenced from:
      _main in main.o
  "_glfwInit", referenced from:
      _main in main.o
  "_glfwMakeContextCurrent", referenced from:
      _main in main.o
  "_glfwPollEvents", referenced from:
      _main in main.o
  "_glfwSetInputMode", referenced from:
      _main in main.o
  "_glfwSwapBuffers", referenced from:
      _main in main.o
  "_glfwTerminate", referenced from:
      _main in main.o
  "_glfwWindowHint", referenced from:
      _main in main.o
  "_glfwWindowShouldClose", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

很明显这是一个链接错误。做了一些研究后,我想我发现了我的错误。看来我需要添加GLFW库(libglfw.dylib)以及Cocoa和OpenGL库。我的问题是我找不到libglfw.dylib - 或者其他任何glfw - 在“Link Binary With Libraries”部分下。我找到了OpenGL.framework和Cocoa.framework,但我找不到glfw。我尝试了glfw的整个cmake过程(cmake> make> sudo make install),但它没有显示出来。然后我尝试使用brew进行安装,但这也无效。我无法弄清楚为什么我找不到这个文件。有任何想法吗?这是我第一次使用GLFW和我在OSX上进行任何编码的第一个项目。如果我忘记了您需要的任何信息,请尽快告诉我,我会尽快给您。

1 个答案:

答案 0 :(得分:0)

首先,在OS X上使用GLEW是100%无意义的(OpenGL扩展在此平台上的链接时都是静态处理的)。您应该为项目添加一些代码,这些代码可以执行以下操作:

#ifndef __APPLE__
  // GLEW-specific code here
#endif

此外,.dylib用于动态链接 - 在OS X上没有太多意义.GLFW不是以Framework的形式分发的,您必须编译它你自己。如果您愿意,您仍然可以使用GLFW的动态链接版本,但是您最终必须将库打包到.app包中。我建议你只使用静态版本并避免所有这些。

您是否查看过the GLFW compilation instructions的OS X部分?