Could not find moc executable target Qt6::moc
-
I'm trying to build linuxdeployqt and when running CMake it can't find Qt6::moc.
CMake Error: AUTOMOC for target linuxdeployqt: Could not find moc executable target Qt6::moc CMake Generate step failed. Build files cannot be regenerated correctly.
The
CMakeLists.txt
usesset(CMAKE_AUTOMOC ON)
.I have installed Qt 6.5.3 using the maintenance tool and it works correctly for a different qmake project and
qmake -query
seems to be able to locatemoc
correctly$ qmake -query QT_INSTALL_LIBEXECS /home/glenn/Qt/6.5.3/gcc_64/libexec $ `qmake -query QT_INSTALL_LIBEXECS`/moc --version moc 6.5.3
$ cmake --version cmake version 3.27.7
What could the problem here and how can I fix or work around it?
-
-
It did not work on my computer, and the cmake output get more complicated. It indicated a path name error when I attempted to remove 'QT' or 'NAMES' or both them.
@Sayuqwq Hi and welcome to devnet,
One simple way to use cmake is to in fact use the
qt-cmake
wrapper that is contained in the Qt 6 installation you want to use. Otherwise, use theCMAKE_PREFIX_PATH
to point cmake to the Qt version you want to use. -
This post is deleted!
-
The fix that works for me (tm) is:
find_package(QT NAMES Qt6 Qt5) find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Test)
Needed to use CMAKE_PREFIX_PATH for this to work. Just setting QT_DIR / QT did not.