特征C++库给出了C++11选项的错误

Eigen C++ Library gives error with C++ 11 option

本文关键字:C++11 选项 错误 C++ 特征      更新时间:2023-10-16

我有下面的C++代码,其中我使用了Eigen C++库。

#include "Dense"
#include <iostream>
int main()
{
    Eigen::MatrixXf x(10,10);
    x.setRandom();
    std::cout<<"x is ..n"<<x<<std::endl;

    return 0;
}

当我用"-std=gnu++11"尝试g++时,会出现以下错误。

In file included from /usr/include/c++/4.8/tuple:39:0,
                 from /usr/include/c++/4.8/functional:55,
                 from ../SP_ToolBox/ExternalLibraries/Eigen/Eigen/Core:153,
                 from ../SP_ToolBox/ExternalLibraries/Eigen/Eigen/Dense:1,
                 from test.cpp:1:
../SP_ToolBox/ExternalLibraries/Eigen/Eigen/array:8:4: error: #error The Eigen/Array header does no longer exist in Eigen3. All that functionality has moved to Eigen/Core.
   #error The Eigen/Array header does no longer exist in Eigen3. All that functionality has moved to Eigen/Core.
    ^
In file included from /usr/include/c++/4.8/functional:55:0,
                 from ../SP_ToolBox/ExternalLibraries/Eigen/Eigen/Core:153,
                 from ../SP_ToolBox/ExternalLibraries/Eigen/Eigen/Dense:1,
                 from test.cpp:1:
/usr/include/c++/4.8/tuple:885:33: error: ‘array’ was not declared in this scope
     struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type
                                 ^
/usr/include/c++/4.8/tuple:885:44: error: wrong number of template arguments (2, should be 1)
     struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type
                                            ^
/usr/include/c++/4.8/tuple:873:12: error: provided for ‘template<class> struct std::__is_tuple_like_impl’
     struct __is_tuple_like_impl : false_type
            ^
/usr/include/c++/4.8/tuple:885:47: error: expected unqualified-id before ‘>’ token
     struct __is_tuple_like_impl<array<_Tp, _Nm>> : true_type

如果我去掉"-std=gnu++11"选项,它编译得很好。我的gcc版本是4.8.4,特征库版本是3.2.10。

您似乎已经将Eigen include目录直接放在了头文件搜索路径上。这意味着当包含标准<array>头文件时,编译器实际上会包含Eigen array头文件。

将您的-I标志更改为不包括完整路径,仅包括例如../SP_ToolBox/ExternalLibraries/Eigen(即丢弃最后一个/Eigen(。

然后改为包含<Eigen/Dense>