eigen3 编译报错
错误信息:
/usr/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h:254:30: error: redeclared with 1 template parameter
254 | template <typename T> struct array_size;
/usr/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h:255:41: error: redefinition of ‘struct Eigen::internal::array_size<const std::array<_Tp, _Nm> >’
255 | template<class T, std::size_t N> struct array_size<const std::array<T,N> > {
/usr/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h:258:30: error: redeclared with 1 template parameter
258 | template <typename T> struct array_size;
/usr/include/eigen3/unsupported/Eigen/CXX11/src/util/EmulateArray.h:259:41: error: redefinition of ‘struct Eigen::internal::array_size<std::array<_Tp, _Nm> >’
259 | template<class T, std::size_t N> struct array_size<std::array<T,N> > {
/usr/include/eigen3/unsupported/Eigen/CXX11/src/Tensor/TensorContraction.h:466:111: error: wrong number of template arguments (6, should be at least 7)
466 | internal::gemm_pack_lhs<LhsScalar, Index, typename LhsMapper::SubMapper, mr, Traits::LhsProgress, ColMajor> pack_lhs;
原因: 我装了多个版本的 Eigen 。重复定义。当在代码中使用#include <eigen3/Eigen/Dense>来引用 Eigen,就会在两个路径下找到该文件,于是回报以上的错误。故使用#include <Eigen/Dense>来引用就很保险。
解决办法:
将头文件中的 #include <eigen3/Eigen/Dense>
改为 #include <Eigen/Dense>
便可成功编译!
参考:https://blog.csdn.net/weixin_44401286/article/details/112445309