c++ - 体系结构 x86_64 : "_CFBundleCopyResourceURL", 的 undefined symbol

标签 c++ qt app-bundle cfurl-encoding

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

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

最佳答案

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

LIBS += "-framework CoreFoundation"

关于c++ - 体系结构 x86_64 : "_CFBundleCopyResourceURL", 的 undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30794822/

相关文章:

c++ - 将 string 转换为 char ,空格字符未正确转换

c++ - 水平线的类型是什么?

c++ - Qt 5.1 for OSX 安装仅包含 clang_64 目录,如何使用 macports gcc 进行编译?

ios - 如何将两个 iOS 应用程序捆绑到一个 ipa 文件中

c++ - 访问 XMMATRIX 时 Dx11 崩溃

C++ 正则表达式不理解

c++ - 如何在 gcc 或 clang 中使用 c++20(启用模块)包含多个预编译头

c++ - 问:如何为所有小部件和小部件类型实现通用的基类信号/插槽功能(通过虚拟基类插槽)?

java - 打包在 Mac 应用程序包中时无法访问 Java 资源