C++ Qt CMake没有给出mainwindow.h这样的文件错误
我正在尝试使用Qt5构建CMake文件。CMake在Linux上运行良好,但在Windows上不起作用。Qt版本5.10.1。CMakes在生成时出现错误: moc:/cygdrive/c/../mainwindow.h:没有这样的文件 如何解决这个错误 文件夹结构:C++ Qt CMake没有给出mainwindow.h这样的文件错误,c++,windows,qt,cmake,qt5,C++,Windows,Qt,Cmake,Qt5,我正在尝试使用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_minim
.
├── 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)
您需要将所有头添加到
add_executable
调用中moc
不对源代码执行依赖性分析。尝试了添加可执行文件(instant\u translator mainwindow.h main.cpp mainwindow.cpp${UI\u HEADERS}),出现相同错误。您使用的是cygwin的cmake软件包还是windows软件包?当使用Cygwin时,您需要第一个。是的,我正在运行CLion C:\Users\user\.CLion2017.3\system\Cygwin\u cmake\bin\cmake.exe--build C:\random\u project\cmake build debug--target random\u project--j 2Sorry我没有使用CLion的经验:(