Jig*_*lly 12 c c++ qt cmake qt6
我正在尝试通过 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
Run Code Online (Sandbox Code Playgroud)
运行 cmake-DQt6_DIR=~/Qt/6.5.0/gcc_64/lib/cmake/Qt6
将其添加到您的根 CMakeLists.txt。
\nlist(APPEND CMAKE_PREFIX_PATH "~/Qt/6.3.0/gcc_64")\n
Run Code Online (Sandbox Code Playgroud)\n根据需要更改路径。
\n或者,您可以将其设置为环境变量。
\nexport PATH="~/Qt/6.3.0/gcc_64/:$PATH"\n
Run Code Online (Sandbox Code Playgroud)\n\n\n搜索标准系统环境变量。如果传递 NO_SYSTEM_ENVIRONMENT_PATH 或将 CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH 设置为 FALSE,则可以跳过此操作。以 /bin 或 /sbin 结尾的路径条目会自动转换为其父目录:
\n\n
\n- 小路
\n
CMakefind_package()
搜索路径
\n\n\n在 cmake 特定的缓存变量中指定的搜索路径。这些旨在通过 -DVAR=VALUE 在命令行上使用。这些值被解释为以分号分隔的列表。如果传递 NO_CMAKE_PATH 或将 CMAKE_FIND_USE_CMAKE_PATH 设置为 FALSE,则可以跳过此操作:
\n\n
\n- CMAKE_PREFIX_PATH
\n- CMAKE_FRAMEWORK_PATH
\n- CMAKE_APPBUNDLE_PATH
\n
\n\n\nFIND_XXX() 用于搜索的路径,添加了适当的后缀。\n指定 FIND_XXX() 命令将使用的路径。它包含 \xe2\x80\x9cbase\xe2\x80\x9d 目录,FIND_XXX() 命令将适当的子目录附加到基目录。因此 FIND_PROGRAM() 将 /bin 添加到路径中的每个目录,FIND_LIBRARY() 将 /lib 添加到每个目录,FIND_PATH() 和 FIND_FILE() 将 /include 添加。默认情况下它是空的,它是由项目设置的。另请参见 CMAKE_SYSTEM_PREFIX_PATH、CMAKE_INCLUDE_PATH、CMAKE_LIBRARY_PATH、CMAKE_PROGRAM_PATH。
\n
根据QTBUG-97615,不支持使用 single 配置构建的正确支持Qt6_DIR
(还?),并且配置应用程序构建的“官方”方法是使用CMAKE_PREFIX_PATH
(如其他答案中所建议的)。
但是,如果您的工具不容易支持此类方法(例如 VisualStudio/VSCode),则有一种解决方法可以解决这种情况(我在挖掘 Qt6 的混乱 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 轻松配置。
快乐建设!:)
小智 2
来自Qt 文档:
有多种方法可以告诉 CMake 有关 Qt 的信息,但最常见和推荐的方法是设置 CMake 缓存变量 CMAKE_PREFIX_PATH 以包含 Qt 6 安装前缀。
因此,您应该将 C:/Qt6/6.2.3/mingw_64/ 添加到CMAKE_PREFIX_PATH以分号分隔的列表中。