我有一个CMakeLists.txt文件,如下所示:
# CMakeLists.txt
project(myApp)
# Set minimum version of CMake
cmake_minimum_required(VERSION 3.5)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Find Qt5Core and Qt5Widgets
find_package(Qt5Core REQUIRED)
find_package(Qt5Widgets REQUIRED)
# For finding Qt includes
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${Qt5Widgets_INCLUDE_DIRS})
include_directories(${Qt5Core_INCLUDE_DIRS})
# Collect source files
set(SOURCE
main.cpp
mainwindow.cpp
)
# Collect header files
set(HEADERS
mainwindow.h
)
# Create executable
add_executable(prog ${SOURCE})
# Linking Editor with Qt libraries
target_link_libraries(prog Qt5::Core Qt5::Widgets)
当我运行cmake然后显示以下错误消息时;
Scanning dependencies of target Prog
[ 40%] Building CXX object CMakeFiles/Prog.dir/main.cpp.o
In file included from /path/main.cpp:7:0:
/path/mainwindow.h:7:20: fatal error: QWidgets: No such file or directory
compilation terminated.
我在哪里使用CMake文件做错了?
mainwindow.h
看起来像这样:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
/*
* mainwindow.h
*/
#include <QMainWindow>
#include <QWidgets>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidgets *parent = 0);
~MainWindow();
};
#endif
答案 0 :(得分:2)
应该是
#include <QWidget>
class MainWindow : public QMainWindow
{
...