1. 程式人生 > >【ros_problems】編譯velodyne_poiontcloud提示yaml-cpp出錯解決辦法

【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