Cannot open main.moc Cmake
-
Hello, I have succesfully created a Cmake file to build my qt project, but my other project is a unit test project, the Cmake passess succesfully ( created a VS build ), but when I am trying to launch my UnitTest project it gives a compile error such as:
Cannot open include file: 'main.moc': No such file or directory
And here is my Cmake file:
cmake_minimum_required(VERSION 3.14) project(UnitTests LANGUAGES CXX) set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(Qt5 REQUIRED COMPONENTS Core Network Test ) set(project_headers File1.h File2.h) set(project_sources File1.cpp File2.cpp main.cpp) qt5_wrap_cpp(project_sources_moc ${project_headers}) add_executable(${PROJECT_NAME} ${project_headers} ${project_sources} ${project_sources_moc}) target_link_libraries(${PROJECT_NAME} PUBLIC Qt5::Core Qt5::Network Qt5::Test)
How can I solve this issue? thank you
-
Either use CMAKE_AUTOMOC feature or tell cmake to create a moc file for your main.cpp by adding it to qt5_wrap_cpp or move the class definition into an own header.
See also https://doc.qt.io/qt-5/cmake-manual.html -
Either use CMAKE_AUTOMOC feature or tell cmake to create a moc file for your main.cpp by adding it to qt5_wrap_cpp or move the class definition into an own header.
See also https://doc.qt.io/qt-5/cmake-manual.html@Christian-Ehrlicher well that was it. Thank you)