Reputation: 90
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?
Upvotes: 2
Views: 8406
Reputation: 31
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
Upvotes: 3