编译报错undefined reference to `Sophus::SE3::operator*(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&) 解决方法

一、问题描述

编译程序时遇到如下报错:

/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::operator*(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&) const'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::operator=(Sophus::SE3 const&)'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::SE3()'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::SE3(Eigen::Matrix<double, 3, 3, 0, 3, 3> const&, Eigen::Matrix<double, 3, 1, 0, 3, 1> const&)'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::exp(Eigen::Matrix<double, 6, 1, 0, 6, 1> const&)'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::SE3(Sophus::SE3 const&)'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SE3::operator*(Sophus::SE3 const&) const'
/home/ubuntu/workspace_demo/***/devel/lib/libvikit_common.so: undefined reference to `Sophus::SO3::matrix() const'

二、解决方法

安装非模板类的 Sophus 时,执行完sudo make install,有一个库文件libSophus.so会安装在/usr/local/lib/libSophus.so 。 当在CMake中使用 FIND_PACKAGE(sophus REQUIRED)时,libSophus.so 应该被链接到 Sophus_LIBRARIES, 但cmake却没链接上。

所以,需要在报错的文件所对应的CMakeList.txt 中显示链接到 libSophus.so

find_package(sophus REQUIRED)
set(Sophus_LIBRARIES libSophus.so)
include_directories( ${Sophus_INCLUDE_DIRS} )
target_link_libraries(${PROJECT_NAME} ${Sophus_LIBRARIES})

参考链接

[1] huangweibo. Sophus 编译错误 [EB/OL]. https://blog.csdn.net/u010003609/article/details/68961293, 2017-04-03/2022-11-21.

  • 11
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
根据提供的引用内容,您遇到的问题是在编译时出现了"undefined reference to `Sophus::SE3::SE3()'"和"collect2: error: ld returned 1 exit status"的错误。这通常是由于链接错误引起的。 要解决这个问题,您可以尝试以下几个步骤: 1. 确保您已经正确安装了Sophus库,并且路径设置正确。根据引用中的代码,Sophus库的路径被设置为"/usr/local/lib/libSophus.so"。请确保该路径下存在正确的库文件。 2. 检查CMakeLists.txt文件中的设置是否正确。根据引用中的代码,您需要使用find_package命令找到Sophus库,并将其链接到您的可执行文件中。请确保find_package命令和target_link_libraries命令的设置正确。 3. 检查您的代码中是否正确包含了Sophus库的头文件。根据引用中的代码,您需要包含"sophus/so3.h"和"sophus/se3.h"这两个头文件。请确保这两个头文件的路径设置正确,并且文件存在。 如果您已经尝试了上述步骤但问题仍然存在,您可以尝试以下额外的解决方法: 1. 清理并重新构建您的项目。您可以尝试删除build文件夹,并重新运行cmake和make命令来重新构建项目。 2. 检查您的编译器和链接器是否支持Sophus库的版本。有时候,不同版本的库可能与您的编译器和链接器不兼容,导致链接错误。您可以尝试更新Sophus库的版本或使用与您的编译器和链接器兼容的版本。 3. 如果您使用的是IDE(如CLion),请确保您的项目设置正确,并且Sophus库被正确地包含和链接到项目中。 希望以上解决方法能帮助您解决问题。如果您有任何进一步的问题,请随时提问。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值