macos 上这段程序应该链接什么库


#include <iostream>
#include <stdio.h>
#include <CoreServices/CoreServices.h>

int main()
{
    CSIdentityQueryRef query = CSIdentityQueryCreateForCurrentUser(kCFAllocatorSystemDefault);
    CFErrorRef error;
    uint8 qdata[1024] = {0};
    if (CSIdentityQueryExecute(query, kCSIdentityQueryGenerateUpdateEvents, &error))
    {
        CFArrayRef foundIds = CSIdentityQueryCopyResults(query);
        if (CFArrayGetCount(foundIds) == 1)
        {
            CSIdentityRef userId = (CSIdentityRef) CFArrayGetValueAtIndex(foundIds, 0);
            CFDataRef data = CSIdentityGetImageData(userId);
            CFDataGetBytes(data, CFRangeMake(0, CFDataGetLength(data)), qdata);
        }
    }
    CFRelease(query);
}

这段代码是获取当前用户的头像路径。

我用 g++ 编译的时候报错,

ethson@macbookpro:~/Project/cpp_example$ g++ ./example.cpp -o exam
Undefined symbols for architecture x86_64:
  "_CFArrayGetCount", referenced from:
      _main in example-7e578a.o
  "_CFArrayGetValueAtIndex", referenced from:
      _main in example-7e578a.o
  "_CFDataGetBytes", referenced from:
      _main in example-7e578a.o
  "_CFDataGetLength", referenced from:
      _main in example-7e578a.o
  "_CFRelease", referenced from:
      _main in example-7e578a.o
  "_CSIdentityGetImageData", referenced from:
      _main in example-7e578a.o
  "_CSIdentityQueryCopyResults", referenced from:
      _main in example-7e578a.o
  "_CSIdentityQueryCreateForCurrentUser", referenced from:
      _main in example-7e578a.o
  "_CSIdentityQueryExecute", referenced from:
      _main in example-7e578a.o
  "_kCFAllocatorSystemDefault", referenced from:
      _main in example-7e578a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我猜测是没有链接系统库造成的,但是我查了一圈,也没找到应该链接哪个库,求指教。

阅读 3.5k
1 个回答
g++ ./example.cpp -o exam -framework CoreServices
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进