3

我正在尝试在 eclipse 中的 mac os 10.7 下编译一些东西,并且构建终止于:

  Undefined symbols for architecture x86_64:
  "_kCFAllocatorDefault", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_CFURLCreateWithFileSystemPath", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_CFStringCreateWithCString", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_CFBundleCreate", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_CFBundleGetFunctionPointerForName", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_CFRelease", referenced from:
      ___GLeeGetProcAddress in GLee.o
  "_glGetString", referenced from:
      ___GLeeGetExtensions in GLee.o
      _GLeeGetExtStrGL in GLee.o
      _GLeeInit in GLee.o
     (maybe you meant: _GLee_Lazy_glGetStringi, _GLeeFuncPtr_glGetStringi )
  "___CFConstantStringClassReference", referenced from:
      CFString in GLee.o

所以我知道问题出在 ld 符号上。现在我尝试在 eclipse 中进行项目属性并将 -framework CoreFramework 添加到 g++ 和 gcc 的参数中,但这并没有解决它。

这些符号在哪里,更重要的是 - 我如何将它们添加到我的项目中

4

2 回答 2

5

我通过将 .dylib 添加到链接器来解决此问题。如何设置?

  1. 转到项目属性
  2. 转到 C/C++ 构建 --> 设置
  3. 选择 Mac OS X C++ Linker --> Libraries 这里是棘手的部分......我通过“try-error”方法发现了它是如何工作的:

假设您有一个要添加的 dylib 文件,名为“libMyLib.dylib”,位于 /opt/local/lib/MyLibrary

在显示库的窗口的一部分添加行“MyLib”到显示库搜索路径的窗口的一部分添加行“/opt/local/lib/MyLibrary/”

=> eclipse 将自动执行此操作: 1. 在字符串前面添加“lib” 2. 在字符串后面添加“.dylib”

Mac 还有另一个问题...假设您使用 CoreFoundation 框架中的符号。Mac OS 框架本质上是带有头文件的 dylibs ...如果您不确定,您可以随时通过“file myFile”进行检查

问题是eclipse永远不会正确地从MAC OS SDK和/System/Library/Frameworks/中获取那些dylib,因为它们没有添加.dylib。诀窍是简单地转到 dylib 所在的位置(即使它的名称中没有 .dylib),例如 cd /System/Library/Frameworks/CoreFoundation.framework

然后复制文件并添加dylib(不要重命名!!!)

  file CoreFoundation
  CoreFoundation (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64 
  CoreFoundation (for architecture i386):   Mach-O dynamically linked shared library i386
  #copy the lib and name it to "eclipse friendly format"
  cp CoreFoundation libCoreFoundation.dylib
于 2012-04-02T10:19:25.223 回答
5

您可以使用 -framework 选项,例如 g++ -framework CoreFoundation ..........

于 2012-12-28T14:01:42.670 回答