无法在 ubuntu 上使用 CMake 构建 QT6

发布于 2025-01-14 02:06:05 字数 1754 浏览 1 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

临风闻羌笛 2025-01-21 02:06:05

在 ubuntu 上,qt6-base-dev 包提供 Qt6Config.cmake。这样,cmake 就会找到使用 apt 安装的 qt6 库,而无需使用选项 CMAKE_PREFIX_PATH 来帮助它。

sudo apt install qt6-base-dev

On ubuntu, the package qt6-base-dev provides Qt6Config.cmake. With this, cmake finds the qt6 libraries installed with apt, without helping it with the option CMAKE_PREFIX_PATH.

sudo apt install qt6-base-dev
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文