Eigen C++ 库给出 C++ 11 选项的错误
Eigen C++ Library gives error with C++ 11 option
我有以下使用 Eigen C++ 库的 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,Eigen Library版本是3.2.10.
看来你把Eigen include目录直接放在头文件搜索路径上了。这意味着当包含 standard <array>
头文件时,编译器实际上会包含 Eigen array
头文件。
将您的 -I
标志更改为不包含完整路径,例如最多只包含../SP_ToolBox/ExternalLibraries/Eigen
(即删除最后一个 /Eigen
)。
然后包括 <Eigen/Dense>
。
我有以下使用 Eigen C++ 库的 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,Eigen Library版本是3.2.10.
看来你把Eigen include目录直接放在头文件搜索路径上了。这意味着当包含 standard <array>
头文件时,编译器实际上会包含 Eigen array
头文件。
将您的 -I
标志更改为不包含完整路径,例如最多只包含../SP_ToolBox/ExternalLibraries/Eigen
(即删除最后一个 /Eigen
)。
然后包括 <Eigen/Dense>
。