【问题标题】:Including Eigen with QtCreator - Red errors showing in source file even though the code works?包括带有 QtCreator 的 Eigen - 即使代码有效,源文件中也会显示红色错误?
【发布时间】:2020-01-26 11:18:53
【问题描述】:

我刚刚开始使用 QtCreator(以及 15 年后的 C++)。我想做一些线性代数的事情,所以我在我的项目文件中包含了 Eigen 库,如下所示(我暂时将 Eigen 库直接放在我的项目中):

INCLUDEPATH = "/home/Software/QtProjects/MyProject/eigen/"

我的源文件是:

#include <QCoreApplication>
#include <iostream>
#include <Eigen/Dense> % 'Eigen/Dense' file not found

using Eigen::MatrixXd; % use of undeclared identifier 'Eigen'

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    MatrixXd m(2,2); % unknown type name 'MatrixXd'

    m(0,0) = 3;
    m(1,0) = 2.5;
    m(0,1) = 8;
    m(1,1) = m(1,0) + m(0,1);
    std::cout << m << std::endl;

    return a.exec();
}

此代码工作并在控制台中输出矩阵m 的值。但是,在 QtCreator IDE 中,我有几条错误消息,我在上面将它们作为 cmets 包含在它们出现的行上。

那么有什么方法可以解决这个问题,让 QtCreator 在代码实际运行正常时停止将这些行显示为错误?

【问题讨论】:

    标签: qt qt-creator eigen


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      在 Linux 上,运行

      sudo apt-get install libeigen3-dev
      

      然后将其添加到您的 .pro 文件中

      INCLUDEPATH += /usr/include/eigen3
      

      然后运行 ​​qmake

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多