Soo Soo - 1 month ago 14
C++ Question

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

I have the following C++ code where I used 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;
}


When I try g++ with "-std=gnu++11" it gives the following error.

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


It compiles fine if I remove "-std=gnu++11" option.
My gcc version is 4.8.4 and Eigen Library version is 3.2.10.

Answer

It seems that you have put the Eigen include directory directly on the header file search path. That means when the standard <array> header file is included, the compiler will actually include the Eigen array header file instead.

Change your -I flag to not include the full path, only up to e.g. ../SP_ToolBox/ExternalLibraries/Eigen (i.e. drop the last /Eigen).

Then include <Eigen/Dense> instead.