【问题标题】:Build specific modules in Qt6 (i.e. QtMqtt)在 Qt6 中构建特定模块(即 QtMqtt)
【发布时间】:2021-10-25 21:53:09
【问题描述】:

对于使用 MQTT 的项目,我总是必须从源代码编译 QtMqtt 模块,因为它不包含在预构建的 Windows 版本中,也无法选择安装。在 Qt5 中这很容易:从官方 git (https://code.qt.io/cgit/qt/qtmqtt.git/) 下载源代码,在 QtCreator 中打开 .pro 文件并编译项目。安装时,我只是将 .dll 文件移动到我的 Qt 安装目录。

现在在 Qt6 中,构建过程从 qmake 切换到 cmake,所以我不能简单地在 QtCreator 中加载项目,而必须使用 CMake 手动编译它,我觉得这非常不直观且容易出错。据我了解,从现在开始我无法自行编译单个模块,而是必须获取整个 Qt 6.2.0 源代码(即通过安装程序选项),然后在 CMake 上使用 --target 选项来构建特定的模块。所以这是我到目前为止所做的:

  1. 从安装程序获取Qt源代码(安装到Qt/6.2.0/Src
  2. 根据this manual创建命令行环境
  3. 打开cmd环境,导航到build文件夹(即Qt/6.2.0/build
  4. 使用命令配置构建:..\Src\configure -prefix Qt\6.2.0\build
  5. 使用命令cmake --build . --target qtmqtt 使用cmake 构建
  6. 使用命令cmake --install .安装

发生的情况是,配置有效,并且构建也应该有效,但安装失败,如下所示:

CMake Error at qtbase/src/3rdparty/libpng/cmake_install.cmake:41 (file):
  file INSTALL cannot find
  "F:/DEV/prog/Qt/6.2.0/build/qtbase/mkspecs/modules/qt_ext_libpng.pri": File
  exists.
Call Stack (most recent call first):
  qtbase/src/3rdparty/cmake_install.cmake:42 (include)
  qtbase/src/cmake_install.cmake:42 (include)
  qtbase/cmake_install.cmake:244 (include)
  cmake_install.cmake:42 (include)

文件夹Qt/6.2.0/build 然后只包含 .cmake 文件,但对我来说似乎没有任何可用的 .dll 文件。我只是不明白如何使用 cmake 正确设置所有内容。既然在 Qt5 中用 qmake 编译模块相当容易,为什么他们现在要把它弄得这么复杂?

【问题讨论】:

    标签: c++ qt cmake qt6


    【解决方案1】:

    尝试用cmake --install qtmqtt替换cmake --install .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 2018-10-13
      • 1970-01-01
      • 2018-09-17
      • 2021-03-20
      • 2021-12-15
      相关资源
      最近更新 更多