semantic icp编译相关问题

项目场景:

在Ubuntu18上编译semantic icp


问题描述

已经正确安装eigen3.3.4和sophus库,在cmake过程出现以下问题:提示找不到eigen3

 Found package configuration file:

    /usr/local/share/sophus/cmake/SophusConfig.cmake

  but it set Sophus_FOUND to FALSE so package "Sophus" is considered to be
  NOT FOUND.  Reason given by package:

  Sophus could not be found because dependency Eigen3 could not be found.

解决方案:

首先确定eigen3和sophus正确安装,且单独编译eigen3是可以编译通过的。第一种解决方法:在CMakeLists.txt中将eigen3和sophus相关的路径直接添加到文件中。并且将findEigen3文件复制到CMakeLists.txt所在的目录下。

set(EIGEN3_INCLUDE_DIR "/usr/include/eigen3")

# include_directories(${EIGEN3_INCLUDE_DIR})

find_package(Eigen3 REQUIRED)

include_directories((EIGEN3_INCLUDE_DIR))

set(Sophus_DIR "/usr/local/include/sophus")

find_package(Sophus REQUIRED)

include_directories((Sophus_DIR))

依然提示原有错误。

又查看了CMakeError.log,错误如下:

Determining if the pthread_create exist failed with the following output:

Change Dir: /home/qxn/code/semantic-icp/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_a658e/fast"

/usr/bin/make -f CMakeFiles/cmTC_a658e.dir/build.make CMakeFiles/cmTC_a658e.dir/build

make[1]: 进入目录“/home/qxn/code/semantic-icp/build/CMakeFiles/CMakeTmp”

Building C object CMakeFiles/cmTC_a658e.dir/CheckSymbolExists.c.o

/usr/bin/cc -o CMakeFiles/cmTC_a658e.dir/CheckSymbolExists.c.o -c /home/qxn/code/semantic-icp/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c

Linking C executable cmTC_a658e

/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a658e.dir/link.txt --verbose=1

/usr/bin/cc -rdynamic CMakeFiles/cmTC_a658e.dir/CheckSymbolExists.c.o -o cmTC_a658e

CMakeFiles/cmTC_a658e.dir/CheckSymbolExists.c.o:在函数‘main’中:

CheckSymbolExists.c:(.text+0x1b):对‘pthread_create’未定义的引用

collect2: error: ld returned 1 exit status

CMakeFiles/cmTC_a658e.dir/build.make:97: recipe for target 'cmTC_a658e' failed

make[1]: *** [cmTC_a658e] Error 1

make[1]: 离开目录“/home/qxn/code/semantic-icp/build/CMakeFiles/CMakeTmp”

Makefile:126: recipe for target 'cmTC_a658e/fast' failed

make: *** [cmTC_a658e/fast] Error 2

出现此错误的原因是

错误信息 “undefined reference to ‘pthread_create’” 是一个链接器错误。这意味着编译器找到了 ‘pthread_create’ 函数的声明,但在链接阶段没有找到它的定义。

这是因为 pthread 不是 Linux 中的默认库,所以在链接时,它无法在 pthread 库中找到函数的入口地址。

要解决这个问题,你需要链接 pthread 库。你可以通过在 gcc 命令中添加 -lpthread 来实现这一点。如果你正在使用 CMake,你可以在你的 CMakeLists.txt 文件中添加 set(THREADS_PREFER_PTHREAD_FLAG ON) 和 find_package(Threads REQUIRED),然后用 ${CMAKE_THREAD_LIBS_INIT} 链接你的目标。

 cmake通过。


注意此时需要保证ceres版本与eigen版本对应,由于我一开始安装的eigen版本的3.3.0,此时如果不重新安装ceres,编译会报错:

CMake Error at CMakeLists.txt:26 (find_package):
  Found package configuration file:

    /usr/local/lib/cmake/Ceres/CeresConfig.cmake

  but it set Ceres_FOUND to FALSE so package "Ceres" is considered to be NOT
  FOUND.
 

解决方法是:1. 重新安装ceres 2.更改/usr/local/lib/cmake/Ceres/CeresConfig.cmake文件,添加

set (CERES_EIGEN_VERSION 3.3.4),然后在ceres文件夹build目录下重新

cmake

make

sudo make install

编译通过。


此时继续编译又遇到了以下问题:

在函数‘fmt::v8::appender fmt::v8::detail::write<char, fmt::v8::appender>(fmt::v8::appender, fmt::v8::basic_string_view<fmt::v8::type_identity<char>::type>, fmt::v8::basic_format_specs<char> const&, fmt::v8::detail::locale_ref) [clone .isra.1371]’中: test_gradient.cc:(.text+0x1f2):对‘fmt::v8::detail::assert_fail(char const*, int, char const*)’未定义的引用 test_gradient.cc:(.text+0x201):对‘fmt::v8::detail::error_handler::on_error(char const*)’未定义的引用 ‘’

 原因:

这个错误可能是由于fmt库的版本问题导致的。在你的代码中,你可能使用了fmt库的某个版本,但是在链接时使用的fmt库版本却不同。这可能会导致一些函数或符号未定义的问题icon-default.png?t=N7T8https://blog.csdn.net/weixin_53660567/article/details/120328579

解决这个问题的一种方法是确保你的代码和链接时使用的fmt库版本一致。你可以检查你的系统中安装的fmt库版本,然后确保你的代码中使用的是相同的版本icon-default.png?t=N7T8https://blog.csdn.net/weixin_53660567/article/details/120328579

另一种可能的解决方案是更新你的fmt库到最新版本。这可以通过下载最新版本的源代码,然后编译和安装来完成icon-default.png?t=N7T8https://blog.csdn.net/weixin_53660567/article/details/120328579

为了方便,我直接重新安装了fmt,但是依然报错。解决方法:

这可能是由于fmt库的某些部分与您的项目或其他库存在冲突。这里有一些可能的解决方案:

  1. 在源代码中定义FMT_HEADER_ONLY:这是一种常见的解决方法,特别是当您只是使用C++来编写算法时icon-default.png?t=N7T8https://bing.com/search?q=fmt%E5%BA%93%E6%9B%B4%E6%96%B0%E5%90%8E%E4%BB%8D%E7%84%B6%E5%87%BA%E7%8E%B0%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95可以在包含fmt/format.h的地方之前添加以下代码:

    #define FMT_HEADER_ONLY
    #include <fmt/format.h>
    
  2. 在编译命令中添加-lfmt参数:另一种方法是在编译命令中添加-lfmt参数,或者链接到"/usr/local/lib/libfmt.a"icon-default.png?t=N7T8https://bing.com/search?q=fmt%E5%BA%93%E6%9B%B4%E6%96%B0%E5%90%8E%E4%BB%8D%E7%84%B6%E5%87%BA%E7%8E%B0%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95

  3. 添加-fPIC编译选项:如果您在链接时遇到关于relocation R_X86_64_32S的错误,您可以尝试在CMakeLists.txt文件中添加-fPIC编译选项icon-default.png?t=N7T8https://blog.csdn.net/weixin_33566282/article/details/124166346这个选项用于将静态库链接成.so动态库。您可以通过以下方式添加此选项:

    add_compile_options(-fPIC)

我选了第一种,在编译时哪个文件提示错误就在哪个文件中添加代码 。

编译通过。


在../build/exec下运行./test_gradient可以正常执行。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值