1

背景

我目前正在使用 Eclipse Neon.3 并安装了“C/C++ CMake Build Support - Experimental”包(我没有使用 CMake 的 Eclipse 生成器)。我有一个使用成功构建的 Qt 5.8 的简单程序,但是,Eclipse 似乎无法索引 Qt 符号(例如 QCoreApplication、QDebug 等)。

这种情况的症状是:

  • 没有代码完成建议
  • #include <QtCore>和其他包含语句显示为未解决
  • Qt 符号,如QCoreApplicationQDebug()QCoreApplication.exec()显示为未解析。

代码

CMakeLists.txt文件

cmake_minimum_required(VERSION 3.5)
project(test-program)

set(CMAKE_CXX_STANDARD 11)

# Put the CMake files for Qt5 in the Prefix path.
set(Qt5_DIR /opt/Qt/5.8/gcc_64/lib/cmake/Qt5/)

#Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)

#Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)

#Find the Qt5Core Library
find_package(Qt5 REQUIRED COMPONENTS Core Widgets)

set(SOURCE_FILES
    src/main.cpp)

add_executable(${PROJECT_NAME} ${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME} Qt5::Core) 

main.cpp(与 Eclipse 注释一起显示)

#include <QtCore> //Unresolved inclusion: <QtCore>
#include <QDebug> //Unresolved inclusion: <QDebug>

int main(int argc, char** argv){
    QCoreApplication application(argc, argv); 
    //Type 'QCoreApplication' could not be resolved 

    qDebug() << "Test";
    //Function 'qDebug' could not be resolved

    application.exec();
    //Method 'exec' could not be resolved

    return 0;
}

问题

所以我的问题是:如何让 Eclipse 识别 Eclipse 识别 Qt 符号?或者这在这个时候是不可能的?

4

1 回答 1

1

您是否启用了“CDT GCC Build Output Parser”?这是一个 Eclipse 功能,用于解析构建的输出并自动猜测包含路径。您可以在Project Properties->C/C++ General->Preprocessor Include Paths, Macros etc.下找到它,然后在Providers选项卡下找到它。

为了使此功能正常工作,必须生成详细的构建报告。您可以通过将Preferences->C/C++ Build下的构建命令更改为make VERBOSE=1或通过set(CMAKE_VERBOSE_MAKEFILE On)在 CMakeLists.txt 中指定来实现此目的。

另请参阅Eclipse 帮助 - 扫描仪发现首选项

于 2017-06-06T08:20:26.873 回答