未定义的符号 建筑x86_64的未定义符号:"_kCFAllocatorDefault"

undefined symbols Undefined symbols for architecture x86_64: "_kCFAllocatorDefault"

本文关键字:未定义 符号 kCFAllocatorDefault x86 建筑      更新时间:2023-10-16

我正试图在eclipse中的macos10.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中的g++和gcc的参数中添加-framework CoreFramework,但这并没有解决问题

这些符号位于何处,更重要的是-我如何将它们添加到我的项目中?

我通过向链接器添加.dylib来修复此问题。如何设置?

  1. 转到项目礼仪
  2. 转到C/C++构建-->设置
  3. 选择Mac OS X C++链接器-->库以下是棘手的部分……我通过"尝试错误"方法找到了它的工作原理:

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

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

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

Mac出现了另一个问题。。。假设您使用CoreFoundation框架中的符号。Mac操作系统框架本质上是带有头文件的dylib。。。如果你不确定你可以随时通过"文件myFile"检查

问题是eclipse永远不会正确地从MAC OS SDK和/System/Library/Frameworks/中获取这些dylib,因为它们没有添加.dlib。诀窍是简单地去dylib所在的地方(即使它的名字中没有.dlib)。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

您可以使用-framework选项例如g++框架CoreFoundation。。。。。。。。。。