1.错误现象:
Environment :ubuntu18.04 ,rosl:Melodic
boost1.65.1: header files' path : /usr/include , boost lib path: /usr/lib/x86_64-linux-gnu/
boost1.58: header files' path : /usr/local/include , boost lib path: /usr/local/lib/
use the following command to compile moveit,
catkin build -j2 -DBOOST_LIBRARYDIR=/usr/lib/x86_64-linux-gnu/ -DBOOST_INCLUDEDIR=/usr/include
err occurs:
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::cpp_regex_traits_implementation::transform[abi:cxx11](char const*, char const*) const’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::raise_runtime_error(std::runtime_error const&)’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::put_mem_block(void*)’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator > > > >, boost::regex_traits<char, boost::cpp_regex_traits > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits > > const&, boost::regex_constants::_match_flags)’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::get_mem_block()’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::get_default_error_string(boost::regex_constants::error_type)’Undefined reference
/home/xxx/ws_moveit-dual_panda/devel/lib/libmoveit_test_utils.so.1.1.1:对‘boost::re_detail::cpp_regex_traits_implementation::transform_primary[abi:cxx11](char const*, char const*) const’Undefined reference
collect2: error: ld returned 1 exit status
moveit/moveit_core/robot_state/CMakeFiles/robot_state_benchmark.dir/build.make:182: recipe for target '/home/xxx/ws_moveit-dual_panda/devel/lib/moveit_core/robot_state_benchmark' failed
make[2]: *** [/home/xxx/ws_moveit-dual_panda/devel/lib/moveit_core/robot_state_benchmark] Error 1
CMakeFiles/Makefile2:12960: recipe for target 'moveit/moveit_core/robot_state/CMakeFiles/robot_state_benchmark.dir/all' failed
make[1]: *** [moveit/moveit_core/robot_state/CMakeFiles/robot_state_benchmark.dir/all] Error 2
[ 53%] Built target my_mtc_demos_lib2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j2" failed
and I found that ,boost::re_detail in boost-1.58 but not found boost::re_detail in boost-1.65
but, ros-melodic depend on boost-1.65 ,so how can I solve the problem
2.解决办法:
通过meld对比两个版本的boost中的instances.hpp
发现1.65.1中文件
1.58中文件
两者都有一个
#ifndef BOOST_NO_STD_ALLOCATOR
#endif
所以由此可知在编译boost的时候只要将该宏定义BOOST_NO_STD_ALLOCATOR改写即可,
搜索到:则只需要下载boost_1.65源码重新按照-std=c++11编译即可。
3.下载boost_1.65源码重新按照-std=c++11编译
解压源码进入文件夹,然后依次执行:
./bootstrap.sh --with-libraries=all --prefix=/home/xxx/depend/boost/
./b2 install --prefix=/home/xxx/depend/boost toolset=gcc cxxflags="-std=c++11"
./bootstrap.sh --with-libraries=all --prefix=/home/xxx/depend/boost/
./b2 install --prefix=/home/xxx/depend/boost toolset=gcc cxxflags="-std=c++11"
完成了按照"-std=c++11" 编译的boost的安装,安装到目录/home/xxx/depend/boost/
4.重新编译moveit源码
编译命令为:
catkin build -j2 -DBOOST_LIBRARYDIR=~/depend/boost/lib/ -DBOOST_INCLUDEDIR=~/depend/boost/include
注意:要带着指定的特定版本的boost头文件和库路径,至此完美解决。