我有一个使用 Qt5 的项目,并且我有一个CMakeLists.txt
用于创建 Visual Studio 解决方案的文件。
这是我的摘录CMakeLists.txt
cmake_policy(SET CMP0020 NEW)
set(CMAKE_AUTOMOC ON)
find_package(Qt5 REQUIRED COMPONENTS core widgets)
set(COMMON_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src)
include_directories( ${Boost_INCLUDE_DIRS}
${COMMON_INCLUDE_DIR}
)
file(GLOB_RECURSE COMMON_SOURCE "*.hpp" "*.cpp")
add_library(${PROJECT_NAME} ${COMMON_SOURCE})
qt5_use_modules(${PROJECT_NAME} Widgets)
当我尝试编译代码时,它返回以下错误:
>AUTOMOC : error : C:/Users/.../Projects/MyProject/build/MyProjects_automoc.cpp The file includes the moc file "moc_MyFile.cpp", but could not find header "MyFile{.h,.hh,.h++,.hm,.hpp,.hxx,.in,.txx}" in C:/Users/.../Projects/MyProject/build/
moc 文件已自动生成,并且标头不在 build 文件夹中,而是在 src 目录中的文件夹中。
如何解决此错误?