【ros_problems】编译velodyne_poiontcloud提示yaml-cpp出错解决办法

【ros_problems】编译velodyne_poiontcloud提示yaml-cpp出错解决办法

最近在测试Velodyne,从GitHub上源码安装最新的velodyne_poiontcloud包,它依赖yaml-cpp,从GitHub上可以找到,下载后用Cmake编译安装。

编译velodyne_poiontcloud时发生错误,提示如下:

/usr/bin/ld: /usr/local/lib/libyaml-cpp.a(memory.cpp.o): relocation R_X86_64_32 against `.rodata’ can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libyaml-cpp.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: * [/home/vance/velodyne_ws/devel/lib/libvelodyne_rawdata.so] Error 1
make[1]: * [velodyne/velodyne_pointcloud/src/lib/CMakeFiles/velodyne_rawdata.dir/all] Error 2
make: * [all] Error 2
Invoking “make -j4 -l4” failed

这是因为velodyne_poiontcloud调用了yaml-cpp的共享库(也有叫动态库的,即libyaml-cpp.so这个文件,一般安装在/usr/local/lib/下),而我只有yaml-cpp的静态库(即libyaml-cpp.a这个文件)。

原因在于我在编译yaml-cpp时没有选择编译共享库,其默认编译是生成静态库。参考其README文件,使用-DBUILD_SHARED_LIBS=ON 参数来编译。

Run CMake. The basic syntax is:
cmake [-G generator] [-DBUILD_SHARED_LIBS=ON|OFF] ..
.
yaml-cpp defaults to building a static library, but you may build a shared library by specifying -DBUILD_SHARED_LIBS=ON.

重新编译安装yaml-cpp后,即可解决:

cd [build path of yaml-cpp]
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install

你可能感兴趣的:(ROS,yaml-cpp,velodyne,分享库,静态库)