架构x86_64的未定义符号:"_ CFBundleCopyResourceURL",

Mit*_*l D 0 c++ qt app-bundle cfurl-encoding

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

CFURLRef appUrlRef;


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



qDebug() << filePathRef;

// Release references
CFRelease(filePathRef);
CFRelease(appUrlRef);
Run Code Online (Sandbox Code Playgroud)

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

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"
Run Code Online (Sandbox Code Playgroud)

我在mainwaindow.h中有以下内容

#include <QtCore>
#include <CoreFoundation/CFURL.h>
#include <CoreFoundation/CFBundle.h>
Run Code Online (Sandbox Code Playgroud)

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

Ham*_*att 5

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

LIBS += "-framework CoreFoundation"
Run Code Online (Sandbox Code Playgroud)