我正在尝试使用Qt5构建CMake文件。 CMake在Linux上运行良好,但在Windows上运行不佳。 Qt版本5.10.1。 CMakes在构建时出错: moc:/cygdrive/c /.../mainwindow.h:没有这样的文件
如何解决这个错误?
文件夹结构:
.
├── CMakeLists.txt
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
└── mainwindow.ui
的CMakeLists.txt
cmake_minimum_required(VERSION 3.2)
project(random_project)
set(CMAKE_CXX_STANDARD 11)
# Find includes in corresponding build directories.
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Add Qt CMake path.
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.10.1\\msvc2015\\lib\\")
# Add a compiler flag.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Find the QtWidgets library.
find_package(Qt5Widgets REQUIRED)
# Generate code from UI files.
qt5_wrap_ui(UI_HEADERS mainwindow.ui)
# Tell CMake to create the executable.
add_executable(random_project main.cpp mainwindow.cpp ${UI_HEADERS})
# Use the Widgets module from Qt 5.
target_link_libraries(random_project Qt5::Widgets)