【发布时间】:2022-01-14 09:42:12
【问题描述】:
我正在学习 C++ 和 Qt,并开始尝试使用 QT 构建应用程序。
我使用 cmake 构建,conan 用于包管理器。 通过关注Qt guide for Conan,我得到了一个构建,但是在执行它时,我得到了:
#include <QApplication>
int main(int argc, char **argv) {
QApplication app (argc, argv);
return app.exec();
}
matteo@MacBook-Pro-de-matteo build % export QT_DEBUG_PLUGINS=1
matteo@MacBook-Pro-de-matteo build % ./bin/myapp
QFactoryLoader::QFactoryLoader() ignoring "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3" since plugins are disabled in static builds
qt.qpa.plugin: Could not find the Qt platform plugin "cocoa" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
zsh: abort ./bin/myapp
信息:
matteo@MacBook-Pro-de-matteo everywhere % conan -v
Conan version 1.44.0
matteo@MacBook-Pro-de-matteo everywhere % cmake --version
cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
conanfile.txt:
[requires]
qtbase/6.2.2@qt/everywhere
qt-conan-common/6.2@qt/everywhere
qtdeclarative/6.2.2@qt/everywhere
[generators]
cmake
通过执行以下命令(MacOS)构建库:
conan install ./conanfile.txt --build=missing --profile=conan/qtprofiles/macos-universal-clang --update --generator=VirtualBuildEnv -r qt
我已经将macos-universal-clang的编译器版本改为13,使其与编译器版本匹配,否则无法编译:
macos-universal-clang:
[settings]
os=Macos
os.version=11.0
arch=x86_64
compiler=apple-clang
compiler.version=13.0
compiler.libcxx=libc++
build_type=RelWithDebInfo
[options]
qtbase:release=yes
qtbase:shared=yes
qtbase:nomake=examples;tests
qtbase:force_debug_info=yes
qtbase:separate_debug_info=yes
qtbase:framework=yes
qtbase:cmake_args_qtbase='-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DODBC_ROOT=/usr/local/opt/libiodbc'
*:cmake_args_leaf_module=""
[build_requires]
[env]
编译时找到库:
matteo@MacBook-Pro-de-matteo myxconfig % ./activate.sh
matteo@MacBook-Pro-de-matteo myxconfig % cmake -S . -B out/build
-- Conan: Adjusting output directories
-- Conan: Using cmake global configuration
-- Conan: Adjusting default RPATHs Conan policies
-- Conan: Adjusting language standard
-- Current conanbuildinfo.cmake directory: .../out/build
-- Configuring done
-- Generating done
-- Build files have been written to: ..../out/build
cd out/build
matteo@MacBook-Pro-de-matteo build % make
[100%] Built target myxconfig
matteo@MacBook-Pro-de-matteo myxconfig % echo $?
0
怎么了?
更新
我通过将可可插件静态链接到可执行文件中使其工作:#include <QApplication>
#include <QtPlugin>
Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin)
int main(int argc, char **argv) {
QApplication app (argc, argv);
return app.exec();
}
这是我的灵感来源:https://github.com/siavashk/qt5-static-hello-world
不过,作为一名新生,我仍然在问自己:
- 如果运行的操作系统安装了 lib,如何避免捆绑它并使其正常工作?
- 关于 Qt 所谓的“插件”的简短说明(参考文档)会很棒:)
【问题讨论】: