无法在 ubuntu 上使用 CMake 构建 QT6
我正在尝试在 Ubuntu 20.04 LTS 上手动设置一个使用 QT6 的 CMake 项目。 CMakeLists.txt 如下所示:
cmake_minimum_required(VERSION 3.16)
project(Button, LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "home/ilmu011/Qt/6.2.3/gcc64")
find_package(Qt6 REQUIRED COMPONENTS Widgets)
add_executable(Button
main.cpp
)
但是,CMake 声明它找不到 QT6 安装。它安装在 home/ilmu011/Qt/6.2.3/gcc64 下。但我收到一条错误消息:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/ilmu011/Desktop/Button/build/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1
它告诉我将 CMAKE_PREFIX_PATH 设置为 QT6 位置,我在这里执行了此操作,但它仍然不起作用。我四处寻找解决方案,发现这篇文章:
CMAKE_PREFIX_PATH 没有t help CMake in find Qt5
它说,因为错误消息还指出最终需要一个单独的开发包,最终会提供“qt6-config.cmake” CMake 抱怨不存在,我应该尝试安装这两件事:
sudo apt-get install qtbase5-dev sudo apt-get install qtdeclarative5-dev
但是,这些是针对 QT5 的,但不起作用。如何让 CMake 检测 QT6?
I am trying to manually setup a CMake project that uses QT6 on Ubuntu 20.04 LTS.
This is what the CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.16)
project(Button, LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "home/ilmu011/Qt/6.2.3/gcc64")
find_package(Qt6 REQUIRED COMPONENTS Widgets)
add_executable(Button
main.cpp
)
However, CMake states that it doesn't find the QT6 installation. It is installed under home/ilmu011/Qt/6.2.3/gcc64. But I get an error message:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/ilmu011/Desktop/Button/build/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1
It tells me to set the CMAKE_PREFIX_PATH to the QT6 location, which I did here, but it still doesn't work. I searched around for a solution and found this post:
CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5
It says since the error message also states that eventually a separate development package is required that would eventually provide the "qt6-config.cmake" that CMake complains is not there, I should try installing these two things:
sudo apt-get install qtbase5-dev
sudo apt-get install qtdeclarative5-dev
However, these are for QT5 and that didn't work. How can I get CMake to detect QT6?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 ubuntu 上,
qt6-base-dev
包提供Qt6Config.cmake
。这样,cmake 就会找到使用 apt 安装的 qt6 库,而无需使用选项CMAKE_PREFIX_PATH
来帮助它。On ubuntu, the package
qt6-base-dev
providesQt6Config.cmake
. With this, cmake finds the qt6 libraries installed with apt, without helping it with the optionCMAKE_PREFIX_PATH
.