最近需要在一个现有的ROS程序中用到Open3D,按照官网实例通过源码安装好之后发现编译不通过,提示找不到ROS相关的库,但是把Open3D相关的去掉就可以成功编译。
/usr/bin/ld: CMakeFiles/odometry_node.dir/src/OdometryServer.cpp.o: in function `SigHandle(int)':
OdometryServer.cpp:(.text+0xe9): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
/usr/bin/ld: CMakeFiles/odometry_node.dir/src/OdometryServer.cpp.o: in function `kiss_icp_ros::OdometryServer::lidar_cbk(boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const> const&)':
OdometryServer.cpp:(.text+0xfc4): undefined reference to `ros::console::initializeLogLocation(ros::console::LogLocation*, std::string const&, ros::console::levels::Level)'
/usr/bin/ld: CMakeFiles/odometry_node.dir/src/OdometryServer.cpp.o: in function `kiss_icp_ros::OdometryServer::OdometryServer(ros::NodeHandle const&, ros::NodeHandle const&)':
OdometryServer.cpp:(.text+0x1779): undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
/usr/bin/ld: OdometryServer.cpp:(.text+0x17ce): undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
/usr/bin/ld: OdometryServer.cpp:(.text+0x181d): undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
/usr/bin/ld: OdometryServer.cpp:(.text+0x1869): undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
/usr/bin/ld: OdometryServer.cpp:(.text+0x18b8): undefined reference to `ros::NodeHandle::hasParam(std::string const&) const'
检查了一下CMakeLists.txt也没有什么问题。
cmake_minimum_required(VERSION 3.16...3.24)
project(kiss_icp)
find_package(
catkin REQUIRED
COMPONENTS roscpp
geometry_msgs
nav_msgs
sensor_msgs
rosbag
std_msgs
tf2
tf2_ros)
catkin_package()
find_package(Open3D REQUIRED)
#
# ROS1 node
add_executable(odometry_node src/Utils.cpp src/OdometryServer.cpp src/odometry_node.cpp src/lio_iekf.cpp)
target_link_libraries(odometry_node kiss_icp::pipeline)
target_include_directories(odometry_node PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ${catkin_INCLUDE_DIRS} ${Open3D_INCLUDE_DIRS})
target_link_libraries(odometry_node ${catkin_LIBRARIES} ${Open3D_LIBRARIES})
install(TARGETS odometry_node RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
最后察觉可能是Open3D在编译的时候可能和ROS的某些package有冲突,于是卸载掉Open3D重新编译安装,在cmake的时候加上以下选项,最后编译成功。
cmake -DBUILD_EIGEN3=ON -DBUILD_GLEW=ON -DBUILD_GLFW=ON -DBUILD_JSONCPP=ON -DBUILD_PNG=ON -DGLIBCXX_USE_CXX11_ABI=ON -DPYTHON_EXECUTABLE=/usr/bin/python -DBUILD_UNIT_TESTS=ON ..
参考
https://www.guyuehome.com/36305