macos 将 mac 框架链接到 qt creator

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3513907/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 07:09:33  来源:igfitidea点击:

linking mac framework to qt creator

c++macosqtframeworksqt-creator

提问by Martins

I have a project that uses SystemConfiguration.Framework.

我有一个使用 SystemConfiguration.Framework 的项目。

I've been using xcode, where adding the framework is quite easy, just add it to xcode project's framework. But now, I need my project to be cross platform, so I'm using QT Creator as a single IDE, for Windows and Mac. The problem is that I don't know how to tell QT Creator how to link to the systemConfiguration.framework. The header from the framework are correctly included, no problem there... just when is ending the compilation it complains that some symbols where not found, i.e, the symbols that are exported from the systemconfiguration.framework...

我一直在用xcode,在那里添加框架很容易,只需将其添加到xcode项目的框架中即可。但是现在,我需要我的项目是跨平台的,所以我使用 QT Creator 作为单个 IDE,适用于 Windows 和 Mac。问题是我不知道如何告诉 QT Creator 如何链接到 systemConfiguration.framework。框架中的头文件被正确包含,没问题......就在结束编译时,它抱怨找不到某些符号,即从 systemconfiguration.framework 导出的符号......

Does anyone knows or can help me to set up the Qt creator project to link agains that framework, please?

有谁知道或可以帮助我设置 Qt Creator 项目以重新链接该框架吗?

回答by Troubadour

I assume the project itself is using Qt i.e. it is using .pro files to configure things like include paths and library/framework paths? If so then you just need to update the relevant .pro file to add the framework.

我假设项目本身正在使用 Qt,即它使用 .pro 文件来配置诸如包含路径和库/框架路径之类的东西?如果是这样,那么您只需要更新相关的 .pro 文件即可添加框架。

See the qmake docsfor more detail. The gist of it is to add

有关更多详细信息,请参阅qmake 文档。它的要点是添加

QMAKE_LFLAGS += -F/path/to/framework/directory/

and

LIBS += -framework TheFramework

回答by SyntaX

I found a solution which works with Qt 5.6 here: https://doc.qt.io/qt-5/qmake-platform-notes.html#creating-frameworks

我在这里找到了一个适用于 Qt 5.6 的解决方案:https: //doc.qt.io/qt-5/qmake-platform-notes.html#creating-frameworks

Using Frameworks

qmake is able to automatically generate build rules for linking against frameworks in the standard framework directory on macOS, located at /Library/Frameworks/.

Directories other than the standard framework directory need to be specified to the build system, and this is achieved by appending linker options to the LIBS variable, as shown in the following example:

LIBS += -F/path/to/framework/directory/

The framework itself is linked in by appending the -framework options and the > name of the framework to the LIBS variable:

LIBS += -framework TheFramework

使用框架

qmake 能够自动生成构建规则以链接到 macOS 上标准框架目录中的框架,位于 /Library/Frameworks/。

需要为构建系统指定标准框架目录以外的目录,这是通过将链接器选项附加到 LIBS 变量来实现的,如下例所示:

LIBS += -F/path/to/framework/directory/

框架本身是通过将 -framework 选项和框架的 > 名称附加到 LIBS 变量来链接的:

LIBS += -framework TheFramework