Eigen C++ Library在C++ 11选项中出错

Soo*_*Soo 4 c++ c++11 eigen3

我有以下C++代码,我使用了Eigen C++ Library.

#include "Dense"
#include <iostream>

int main()
{
    Eigen::MatrixXf x(10,10);
    x.setRandom();
    std::cout<<"x is ..\n"<<x<<std::endl;


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我用"-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
Run Code Online (Sandbox Code Playgroud)

如果我删除"-std = gnu ++ 11"选项,它编译正常.我的gcc版本是4.8.4,Eigen Library版本是3.2.10.

Som*_*ude 5

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

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

然后包括<Eigen/Dense>.