c++ CMake在Qt6安装中找不到软件包

nbysray5  于 2023-01-28  发布在  其他
关注(0)|答案(4)|浏览(456)

我正在尝试通过CMake构建一个项目,并将环境变量Qt6_DIR设置为包含Qt6Config.cmake的目录。然而,构建似乎无法在Qt6安装中找到任何其他所需的依赖项&我不确定下一步需要做什么。我看到对其他可能的环境变量的引用,如“Qt6CoreTools_DIR”,并且我“我想知道我是否真的需要单独设置每一个,或者是否有一个包含这些信息的工具链需要正确链接。

-- GUI Frontend: Qt6
CMake Warning at C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  By not providing "FindQt6CoreTools.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Qt6CoreTools", but CMake did not find one.

  Could not find a package configuration file provided by "Qt6CoreTools"
  (requested version 6.2.3) with any of the following names:

    Qt6CoreToolsConfig.cmake
    qt6coretools-config.cmake

  Add the installation prefix of "Qt6CoreTools" to CMAKE_PREFIX_PATH or set
  "Qt6CoreTools_DIR" to a directory containing one of the above files.  If
  "Qt6CoreTools" provides a separate development package or SDK, be sure it
  has been installed.
Call Stack (most recent call first):
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsDependencies.cmake:9 (find_dependency)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsConfig.cmake:34 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsDependencies.cmake:71 (find_package)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake:40 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package)
  src/CMakeLists.txt:22 (find_package)

CMake Warning at C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsDependencies.cmake:71 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6WidgetsTools/Qt6WidgetsToolsConfig.cmake

  but it set Qt6WidgetsTools_FOUND to FALSE so package "Qt6WidgetsTools" is
  considered to be NOT FOUND.  Reason given by package:

  Qt6WidgetsTools could not be found because dependency Qt6CoreTools could
  not be found.

Call Stack (most recent call first):
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake:40 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package)
  src/CMakeLists.txt:22 (find_package)

CMake Warning at C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake

  but it set Qt6Widgets_FOUND to FALSE so package "Qt6Widgets" is considered
  to be NOT FOUND.  Reason given by package:

  Target "Qt6::Widgets" was not found.

Call Stack (most recent call first):
  src/CMakeLists.txt:22 (find_package)

-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR)
CMake Warning at C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Core/Qt6CoreConfig.cmake

  but it set Qt6Core_FOUND to FALSE so package "Qt6Core" is considered to be
  NOT FOUND.  Reason given by package:

  Target "Qt6::Core" was not found.

Call Stack (most recent call first):
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:14 (find_dependency)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLDependencies.cmake:91 (_qt_internal_find_dependencies)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake:40 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package)
  src/CMakeLists.txt:22 (find_package)

CMake Warning at C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake

  but it set Qt6OpenGL_FOUND to FALSE so package "Qt6OpenGL" is considered to
  be NOT FOUND.  Reason given by package:

  Qt6OpenGL could not be found because dependency Qt6Core could not be found.

Call Stack (most recent call first):
  src/CMakeLists.txt:22 (find_package)

-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR)
CMake Warning at C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Core/Qt6CoreConfig.cmake

  but it set Qt6Core_FOUND to FALSE so package "Qt6Core" is considered to be
  NOT FOUND.  Reason given by package:

  Target "Qt6::Core" was not found.

Call Stack (most recent call first):
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:14 (find_dependency)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLDependencies.cmake:91 (_qt_internal_find_dependencies)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake:40 (include)
  C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:14 (find_dependency)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsDependencies.cmake:91 (_qt_internal_find_dependencies)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsConfig.cmake:40 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package)
  src/CMakeLists.txt:22 (find_package)

CMake Warning at C:/Program Files/CMake/share/cmake-3.20/Modules/CMakeFindDependencyMacro.cmake:47 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake

  but it set Qt6OpenGL_FOUND to FALSE so package "Qt6OpenGL" is considered to
  be NOT FOUND.  Reason given by package:

  Qt6OpenGL could not be found because dependency Qt6Core could not be found.

Call Stack (most recent call first):
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:14 (find_dependency)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsDependencies.cmake:91 (_qt_internal_find_dependencies)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsConfig.cmake:40 (include)
  C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package)
  src/CMakeLists.txt:22 (find_package)

CMake Warning at C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsConfig.cmake

  but it set Qt6OpenGLWidgets_FOUND to FALSE so package "Qt6OpenGLWidgets" is
  considered to be NOT FOUND.  Reason given by package:

  Qt6OpenGLWidgets could not be found because dependency Qt6OpenGL could not
  be found.

Call Stack (most recent call first):
  src/CMakeLists.txt:22 (find_package)

CMake Error at src/CMakeLists.txt:22 (find_package):
  Found package configuration file:

    C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6/Qt6Config.cmake

  but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT
  FOUND.  Reason given by package:

  Failed to find Qt component "Widgets".

  Expected Config file at
  "C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake" exists

  Failed to find Qt component "OpenGL".

  Expected Config file at
  "C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGL/Qt6OpenGLConfig.cmake" exists

  Failed to find Qt component "OpenGLWidgets".

  Expected Config file at
  "C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6OpenGLWidgets/Qt6OpenGLWidgetsConfig.cmake"
  exists
pgvzfuti

pgvzfuti1#

把这个添加到根目录cmake中。

list(APPEND CMAKE_PREFIX_PATH "~/Qt/6.3.0/gcc_64")

根据需要更改路径。
或者,您可以将其设置为env var。

export PATH="~/Qt/6.3.0/gcc_64/:$PATH"
iyfamqjs

iyfamqjs2#

根据QTBUG-97615,不支持使用单个Qt6_DIR配置构建版本,配置应用程序构建版本的“官方”方法是使用CMAKE_PREFIX_PATH(如其他答案中所建议)。
然而,如果您的工具不容易支持这种方法(如VisualStudio/VSCode),则有一个解决方案(我在挖掘Qt 6的混乱cmake脚本时发现了它)。

您可以使用QT_ADDITIONAL_PACKAGES_PREFIX_PATH来指定Qt根(与Qt6_DIR沿着在初始时挂钩)。

命令行将如下所示(只是为了说明方法):
cmake -DQt6_DIR:PATH=C:/Qt6/6.2.3/mingw_64/lib/cmake/Qt6 -DQT_ADDITIONAL_PACKAGES_PREFIX_PATH=C:/Qt6/6.2.3/mingw_64 ..
这两个变量都可以通过VisualStudio/VSCode中的UI轻松配置。
快乐的建筑!:)

mmvthczy

mmvthczy3#

Qt Documentation开始:
您可以通过不同的方式告知CMake有关Qt的信息,但最常用和推荐的方法是设置CMake缓存变量CMAKE_PREFIX_PATH以包含Qt 6安装前缀。
因此,您应该将C:/Qt6/6.2.3/mingw_64/添加到CMAKE_PREFIX_PATH分号分隔列表中。

bd1hkmkf

bd1hkmkf4#

您可以检查CMAKE_PREFIX_PATH是否由项目提供的cmake脚本之一设置或修改。

我在Linux操作系统上的另一个项目中遇到了同样的问题,最后似乎奏效的是将一个名为QT_PREFIX的项目特定变量设置为/opt/Qt/6.2.4/gcc_64/
通过查看项目的文件CMakeLists_Dependencies.cmake,我注意到CMAKE_PREFIX_PATH由脚本设置为:我的猜测是,这条语句隐藏了我在命令行中对CMAKE_PREFIX_PATH的定义。
我通过在set(CMAKE_PREFIX_PATH "${QT_PREFIX}/lib/cmake")的正下方插入语句message(CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}")来检查它。
not 设置QT_PREFIX时,输出为CMAKE_PREFIX_PATH="/lib/cmake",无论我是否在命令行中包含-DCMAKE_PREFIX_PATH=…/lib/cmake/在我的例子中 * 不是 * 有效路径)。
如果QT_DIR按照上面的描述进行设置,则输出为CMAKE_PREFIX_PATH="/opt/Qt/6.2.4/gcc_64//lib/cmake",这使得cmake能够找到目录,即使有双斜杠也是如此。

相关问题