【问题标题】:Index Qt5 in Eclipse IDE project using Cmake使用 Cmake 在 Eclipse IDE 项目中索引 Qt5
【发布时间】:2017-10-25 06:16:21
【问题描述】:

背景

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

这种情况的症状是:

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

代码

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 符号?还是目前不可能?

【问题讨论】:

    标签: c++ eclipse cmake qt5.8


    【解决方案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 或在 CMakeLists.txt 中指定 set(CMAKE_VERBOSE_MAKEFILE On) 来实现此目的。

    另见Eclipse Help - Scanner Discovery Preferences

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多