Installed Qt6 to Linux ... cmake ... Target "Qt6::Core" was not found
-
Ran
qt-unified-linux-x64-4.2.0-online.run
to install Qt6 to/usr/local/Qt6
.Set
Qt6_DIR
to/usr/local/Qt6/6.2.3/gcc_64/
.Updated my CMake scripts, replacing all occurences of
Qt5
byQt6
.Running
cmake
. Fails at linefind_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
with error message
-- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR) CMake Warning at /usr/local/Qt6/6.2.3/gcc_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package): Found package configuration file: /usr/local/Qt6/6.2.3/gcc_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): CMakeLists.txt:52 (find_package)
and similar messages for components
Gui
andWidgets
. -
Assuming that Qt6 is installed in
/usr/local/opt/Qt/6.2.3
, the following method succeeds to find Qt6 and its required components:- CMakeLists.txt:
cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(testQt6) set(CMAKE_CXX_STANDARD 17) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
- CMake command:
cmake -B build -DCMAKE_PREFIX_PATH="/usr/local/Qt/6.2.3/gcc_64/lib/cmake"
Tested with CMake 3.22 and Qt 6.2.3 with 'Desktop gcc 64-bit' component installed, on Linux/Debian 11.
-
This looks dubious. Does that also reproduce with a minimal example, or when configuring an example from Qt?
-
Confirm with minimal example:
$ cat CMakeLists.txt cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(libFooBar) set(CMAKE_CXX_STANDARD 17) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets) $ export Qt6_DIR=/usr/local/Qt6/6.2.3/gcc_64/ $ cmake . -- The C compiler identification is GNU 11.2.0 -- The CXX compiler identification is GNU 11.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/lib/ccache/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/lib/ccache/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Check if compiler accepts -pthread -- Check if compiler accepts -pthread - yes -- Found Threads: TRUE -- Performing Test HAVE_STDATOMIC -- Performing Test HAVE_STDATOMIC - Success -- Found WrapAtomic: TRUE -- Could NOT find Qt6CoreTools (missing: Qt6CoreTools_DIR) CMake Warning at /usr/local/Qt6/6.2.3/gcc_64/lib/cmake/Qt6/Qt6Config.cmake:177 (find_package): Found package configuration file: /usr/local/Qt6/6.2.3/gcc_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): CMakeLists.txt:7 (find_package) -- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so -- Found WrapOpenGL: TRUE -- Could NOT find XKB (missing: XKB_LIBRARY XKB_INCLUDE_DIR) (Required is at least version "0.5.0") -- Found WrapVulkanHeaders: /usr/include -- Could NOT find Qt6GuiTools (missing: Qt6GuiTools_DIR) ...
(corrected; previous version had CMake output obtained with other Qt6_DIR)
-
Assuming that Qt6 is installed in
/usr/local/opt/Qt/6.2.3
, the following method succeeds to find Qt6 and its required components:- CMakeLists.txt:
cmake_minimum_required(VERSION 3.15 FATAL_ERROR) project(testQt6) set(CMAKE_CXX_STANDARD 17) find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
- CMake command:
cmake -B build -DCMAKE_PREFIX_PATH="/usr/local/Qt/6.2.3/gcc_64/lib/cmake"
Tested with CMake 3.22 and Qt 6.2.3 with 'Desktop gcc 64-bit' component installed, on Linux/Debian 11.
-
-
Finding Qt just by setting
Qt6_DIR
currently does not work.
That is tracked in https://bugreports.qt.io/browse/QTBUG-97615 and will be fixed in a future Qt version, but only for desktop platforms.For cross-compiled Qt, that won't be sufficient. For details, check https://forum.qt.io/topic/137551/cmake-finds-cross-compiled-qt6-config-files-but-qt6_found-is-set-to-false/5