EIGEN中文件重定义解决办法error: redefinition of template<class MatrixType, class RealScalar, class Index> 解决办法

转:EIGEN中文件重定义解决办法

https://blog.csdn.net/weixin_44401286/article/details/112445309

Error: redefinition of template<class MatrixType, class RealScalar, class Index> 解决办法

复古蓝 2021-01-10 21:56:57  74  已收藏 2
分类专栏: Ubuntu SLAM 文章标签: redefinition of template Eigen _jacobi_svd JacobiRotation
版权
调试代码是编译报错如下:

/usr/local/include/eigen3/Eigen/src/misc/RealSvd2x2.h:19:6: error: redefinition of ‘template<class MatrixType, class RealScalar, class Index> void Eigen::internal::real_2x2_jacobi_svd(const MatrixType&, Index, Index, Eigen::JacobiRotation<RealScalar>*, Eigen::JacobiRotation<RealScalar>*)’
 void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,
      ^
In file included from /usr/include/eigen3/Eigen/SVD:36:0,
                 from /usr/include/eigen3/Eigen/Geometry:15,
                 from /usr/include/pcl-1.7/pcl/point_cloud.h:47,
                 from /home/ipsg/study/ROS_Load_Ply/src/Load_ply.cpp:2:
/usr/include/eigen3/Eigen/src/SVD/JacobiSVD.h:405:6: note: ‘template<class MatrixType, class RealScalar, class Index> void Eigen::internal::real_2x2_jacobi_svd(const MatrixType&, Index, Index, Eigen::JacobiRotation<RealScalar>*, Eigen::JacobiRotation<RealScalar>*)’ previously declared here
 void real_2x2_jacobi_svd(const MatrixType& matrix, Index p, Index q,


原因分析: Eigen::internal::real_2x2_jacobi_svd编译器检测到定义了两次,网上找到的解决办法大多是重装Eigen,但是貌似没什么作用(针对某些情况可用,并不普适)…比如,我用这种方法就解决不了问题。
不过,归根结底还是因为两次找到了同一个定义,以此入手去解决问题。首先对于Eigen的安装不过是将库文件拷贝在特征的文件夹中,如因为eigen3 被默认安装到了usr/local/include里了(或者是usr/include里,这两个都差不多,都是系统默认的路径)。一般情况下这两个路径都可以,最好确保两路径下的使用的Eigen版本相同,可避免一些麻烦。通常为了使用方便,在安装是会如下操作进行文件copy:

sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include 
1
综上,就很可能存在一个问题,当在代码中使用#include <eigen3/Eigen/Dense>来引用Eigen,就会在两个路径下找到该文件,于是回报以上的错误。故使用#include <Eigen/Dense>来引用就很保险。
解决办法:
将头文件中的#include <eigen3/Eigen/Dense>改为#include <Eigen/Dense>便可成功编译!
 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值