簡體   English   中英

使用 cmake 和柯南構建時,qt 未正確鏈接

[英]qt is not linked correctly when building with cmake and conan

我正在學習 C++ 和 Qt 並開始嘗試使用 QT 構建應用程序。

我正在使用 cmake 來構建,並為 package 管理器使用柯南。 通過遵循柯南的 Qt 指南,我得到了一個構建,但是在執行它時,這就是我得到的:

#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).

柯南文件.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

怎么了?

更新

我通過將 cocoa 插件靜態鏈接到可執行文件中使其工作:
 #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 所謂的“插件”(參考文檔)的簡短說明會很棒:)

此消息不是關於鏈接,而是關於 Qt 運行時無法找到文件:

qt.qpa.plugin:在“”中找不到 Qt 平台插件“cocoa”

要么設置環境變量:

QT_QPA_PLATFORM_PLUGIN_PATH=/home/me/.conan/data/qt/5.12.0/repo/stable/package/f3d861c7053b683d8cf8fcd66b11dc1dee351153/plugins

或者

QT_PLUGIN_PATH=/home/me/.conan/data/qt/5.12.0/repo/stable/package/f3d861c7053b683d8cf8fcd66b11dc1dee351153/plugins

根據經驗,其中之一應該取決於 Qt 構建,但請注意您的本地系統路徑。 以上來自 Linux 項目,我們為其他平台創建類似的項目。 因此,我們的安裝程序會創建啟動腳本文件start.sh ,如下所示:

QT_PLUGIN_PATH=/home/me/.conan/data/qt/5.12.0/repo/stable/package/f3d861c7053b683d8cf8fcd66b11dc1dee351153/plugins
/home/me/progPath/bin/qtProgram

請注意,以上不是規則,可能取決於安裝設置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM