分步骤编译安装Cartographer

编译环境:Ubuntu20.04;

ROS版本:ROS Noetic;

前言(安装依赖):

sudo apt-get update

sudo apt-get install -y google-mock libboost-all-dev  libeigen3-dev libgflags-dev libgoogle-glog-dev liblua5.2-dev libprotobuf-dev  libsuitesparse-dev libwebp-dev ninja-build protobuf-compiler python-sphinx  ros-melodic-tf2-eigen libatlas-base-dev libsuitesparse-dev liblapack-dev libpcl-dev pcl-tools automake

安装Ceres solver(默认路径为:usr/local/include):

cd ~/Download
git clone https://github.com/Tengyun-Mo/ceres-solver.git
cd ceres-solver
mkdir build
cd build
cmake ..
make -j4
sudo make install
安装protobuf 3.0:
git clone https://github.com/google/protobuf.git

cd protobuf

git checkout v3.6.1

mkdir build

./autogen.sh

./configure

make -j2

sudo make install

sudo ldconfig

正文开始(安装Cartographer):

git clone https://github.com/googlecartographer/cartographer.git

cd cartographer

mkdir build

cd build

cmake .. -DBUILD_SHARED_LIBS=ON

make -j8

sudo make install

这里特别注意一下:目前新版的abseil-cpp对C++编译的版本有要求:

absl/base/policy_checks.h有相关描述,至少要C++14。

// -----------------------------------------------------------------------------
// C++ Version Check
// -----------------------------------------------------------------------------

// Enforce C++14 as the minimum.
#if defined(_MSVC_LANG)
#if _MSVC_LANG < 201402L
#error "C++ versions less than C++14 are not supported."
#endif  // _MSVC_LANG < 201402L
#elif defined(__cplusplus)
#if __cplusplus < 201402L
#error "C++ versions less than C++14 are not supported."
#endif  // __cplusplus < 201402L
#endif

这与2016年发行的Catorgrapher要求支持C++11有冲突。由于使用absl库比较新导致
编译不通过,需修改calmcar_slam/CMakeLists.txt文件添加内容如下:

# ubuntu 11.10将ld的默认选项“--no-as-needed”改为“--as-needed”,会导致旧的库链接时候出错。
# 解决方法:将链接选项选成“--no-as-needed”
# GCC: gcc -Wl,--no-as-needed demo.cpp -lpthread
# Makefile: LDFLAGS += -Wl,--no-as-needed
# CMAKE: SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")

SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")

add_compile_definitions(
    ABSL_LEGACY_THREAD_ANNOTATIONS
)

可以解决类似如下问题:

DBSim.c:(.text+0x38): undefined reference to `dlopen'

DBSim.c:(.text+0x55): undefined reference to `dlerror'

DBSim.c:(.text+0x9c): undefined reference to `dlsym'

DBSim.c:(.text+0xb7): undefined reference to `dlsym'

DBSim.c:(.text+0xd2): undefined reference to `dlsym'

DBSim.c:(.text+0x15d7): undefined reference to `dlclose'

collect2: error: ld returned 1 exit status

某些个别案例还会在make的时候报以下问题:

/usr/bin/ld: /usr/local/lib/liblua.a(loadlib.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO missing from command line

经查,是因为需要链接CMAKE_DL_LIBS库。需修改calmcar_slam/CMakeLists.txt文件添加内容如下(记得加上PUBLIC):

# libdl是动态库,可以用cmake链接进去,所以在CMake官网搜索可得
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_DL_LIBS})

完成Catorgrapher的编译。

正文后续部分(安装catorgrapher_ros_msg,catorgrapher_ros, catorgrapher_rviz):

下载文件:

git clone https://github.com/googlecartographer/cartographer_ros.git

相关功能包从catorgrapher_ros文件夹下面直接拷出来。catorgrapher_ros_msg,catorgrapher_ros, catorgrapher_rviz三个功能包,复制到~/catkin_ws/src/下。

先安装catorgrapher_ros_msg:

catkin_make -DCATKIN_WHITELIST_PACKAGES="cartographer_ros_msg"

在安装catorgrapher_ros:

catkin_make -DCATKIN_WHITELIST_PACKAGES="cartographer_ros"

报GMOCK_LIBRARY库问题,先安装库:

sudo apt install libgmock-dev

然后报一堆语法错误,和安装catorgrapher一样:

SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")

add_compile_definitions(
    ABSL_LEGACY_THREAD_ANNOTATIONS
)

再因为glog库中函数定义的参数格式不对的问题,如下所示:

 cannot convert ‘const tm* const’ to ‘const google::LogMessageTime

是因为ScopedRosLogSink::send函数中参数tm_time的数据格式问题,所用的std::tm*,但是此处tm_time是一个直接的const google::LogMessageTime &logmsgtime的构造函数,查阅了struct GLOG_EXPORT LogMessageTime的构造函数,没有使用std::tm*的,而是使用std::tm的。

void ScopedRosLogSink::send(const ::google::LogSeverity severity,
                            const char* const filename,
                            const char* const base_filename, const int line,
                            // const struct std::tm* const tm_time,
                            const struct std::tm const tm_time,
                            const char* const message,
                            const size_t message_len)
struct GLOG_EXPORT LogMessageTime {
  LogMessageTime();
  LogMessageTime(std::tm t);
  LogMessageTime(std::time_t timestamp, WallTime now);

所以直接将tm*改为tm,同时修改src/cartographer_ros/cartographer_ros/ros_log_sink.cc和ros_log_sink.h的参数类型为tm。

再会报函数override的错误,可以理解为原来准备直接使用tm*算是重载,这下又不重载了,所以把函数后面的override删掉即可。编译完成。

最后安装catorgrapher_rviz。

报一堆语法错误,和安装catorgrapher一样:

SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--no-as-needed")

add_compile_definitions(
    ABSL_LEGACY_THREAD_ANNOTATIONS
)

之后会报一个lua库的问题,提示"lua_newstate’ can not be used when making a shared object; recompile with -fPIC"的问题。

解决方案,重新编译lua。

cd lua-5.3.0/src
rm *.o

curl -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz
tar zxf lua-5.3.0.tar.gz
cd lua-5.3.0
make linux CFLAGS=-fPIC
sudo make install

最后编译完成。Mission complete!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值