体系结构的未定义符号 x86_64:“_CFBundleCopyResourceURL”,

Undefined symbols for architecture x86_64: "_CFBundleCopyResourceURL",

正在尝试使用 Qt 访问 Mac.app 包中资源文件夹的文件路径。这是我的代码:

CFURLRef appUrlRef;


appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("AFE-MP-512"),NULL,NULL);
CFStringRef filePathRef = CFURLCopyPath(appUrlRef);



qDebug() << filePathRef;

// Release references
CFRelease(filePathRef);
CFRelease(appUrlRef);

我唯一拥有的是表单上的按钮 运行 代码。尝试编译时出现以下错误:

Undefined symbols for architecture x86_64:
  "_CFBundleCopyResourceURL", referenced from:
      MainWindow::on_pushButton_clicked() in mainwindow.o
  "_CFBundleGetMainBundle", referenced from:
      MainWindow::on_pushButton_clicked() in mainwindow.o
  "_CFRelease", referenced from:
      MainWindow::on_pushButton_clicked() in mainwindow.o
  "_CFURLCopyPath", referenced from:
      MainWindow::on_pushButton_clicked() in mainwindow.o
  "___CFConstantStringClassReference", referenced from:
      CFString in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ProgramLaunch.app/Contents/MacOS/ProgramLaunch] Error 1
13:18:21: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project ProgramLaunch (kit: Desktop Qt 5.3 clang 64bit)
When executing step "Make"

我在 mainwaindow.h

中包含以下内容
#include <QtCore>
#include <CoreFoundation/CFURL.h>
#include <CoreFoundation/CFBundle.h>

知道哪里出了问题吗?谢谢

您需要link CoreFoundation 框架。您可以将以下内容添加到您的 qmake 项目中:

LIBS += "-framework CoreFoundation"