0

尝试使用 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>

有什么想法可能会出错吗?谢谢

4

1 回答 1

5

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

LIBS += "-framework CoreFoundation"
于 2015-06-12T04:52:22.373 回答