ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# How do i solve this"... .so: undefined reference to '..."

Hi, I have gone through the internet for hours for similar cases to mine but I've tried all solutions and hasn't got my code working. I'm using a library called "vdo_slam" which has been built and can be found in /usr/local/include/vdo_slam. In my project CMakeList.txt I can find_package(vdo_slam REQUIRED) with no error. The only problem I have is at the end of "catkin_build" I get several of these "undefined reference to ...." as shown below. I have tried several solutions as listed below. All these undefined references are declared and defined inside the "vdo_slam" package. Any help is appreciated. Thanks!

Known solutions I have taken:

1. I looked for classes and functions mentioned in the errors and see if there are pure virtual destructors as mentioned in here but they are all defined solidly.

2. I have tried to debug with "readelf" command as shown below referring to this. But i don't have the "libvdo_slam.so" which actually includes these functions in the error. I suppose i need to have "libvdo_slam.so" when i run this "readelf" command right? How can i add that?

Error code from "catkin_build":

/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to typeinfo for VDO_SLAM::Visualizer2D'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to vtable for VDO_SLAM::Visualizer2D'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to vtable for VDO_SLAM::SceneObject'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to VDO_SLAM::BoundingBox::BoundingBox(double, double, double, double)'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to VDO_SLAM::Scene::Scene()'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to VDO_SLAM::Visualizer2D::spinOnce(std::shared_ptr<VDO_SLAM::Scene>&)'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to VDO_SLAM::Scene::add_scene_object(std::shared_ptr<VDO_SLAM::SceneObject>&)'
/home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so: undefined reference to VDO_SLAM::Visualizer2D::Visualizer2D(std::shared_ptr<VDO_SLAM::VisualizerParams>&)'
collect2: error: ld returned 1 exit status
my_realtime_vdo_slam/CMakeFiles/ros_vdoslam_node.dir/build.make:226: recipe for target '/home/tranks/testing_ws/devel/lib/my_realtime_vdo_slam/ros_vdoslam_node' failed
make[2]: *** [/home/tranks/testing_ws/devel/lib/my_realtime_vdo_slam/ros_vdoslam_node] Error 1
CMakeFiles/Makefile2:6593: recipe for target 'my_realtime_vdo_slam/CMakeFiles/ros_vdoslam_node.dir/all' failed
make[1]: *** [my_realtime_vdo_slam/CMakeFiles/ros_vdoslam_node.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j12 -l12" failed


$readelf --dynamic /home/tranks/testing_ws/devel/lib/libmy_realtime_vdo_slam.so Here This is my CMakeList.txt: cmake_minimum_required(VERSION 3.10) project(my_realtime_vdo_slam) find_package(catkin REQUIRED COMPONENTS cv_bridge flow_net geometry_msgs image_transport mask_rcnn message_generation midas_ros mono_depth_2 nav_msgs python_service_starter roscpp sensor_msgs std_msgs tf tf2 tf2_geometry_msgs tf2_ros tf2_sensor_msgs vision_msgs visualization_msgs nodelet message_filters ) find_package(OpenCV) find_package(vdo_slam REQUIRED) ## Generate messages in the 'msg' folder add_message_files( FILES VdoSlamScene.msg VdoSlamMap.msg VdoSceneObject.msg VdoInput.msg ) generate_messages( DEPENDENCIES actionlib_msgs geometry_msgs std_msgs sensor_msgs mask_rcnn vision_msgs ) set(PROJECT_INCLUDE_DIRS include${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}${vdo_slam_INCLUDE_DIRS}
)

include_directories(
${PROJECT_INCLUDE_DIRS} ) catkin_package( INCLUDE_DIRS${PROJECT_INCLUDE_DIRS}
LIBRARIES ${PROJECT_NAME} CATKIN_DEPENDS roscpp image_transport python_service_starter std_msgs tf tf2 tf2_geometry_msgs tf2_ros tf2_sensor_msgs nav_msgs sensor_msgs geometry_msgs cv_bridge flow_net mask_rcnn mono_depth_2 midas_ros message_runtime nodelet message_filters # DEPENDS system_lib ) add_library ... edit retag close merge delete ## Comments 1 [...] I have gone through the internet for hours for similar cases to mine but I've tried all solutions and hasn't got my code working What similar cases, what solutions, and what were the results? This information will help others not suggest things that you've already attempted. Could you please update your question with this information? ( 2021-04-27 17:47:40 -0600 )edit Yes Sorry i put it up in a rush. I have added what I have tried in the post. Please let me know if i need to add anything else. Thanks ( 2021-04-28 01:11:59 -0600 )edit target_link_libraries(${PROJECT_NAME} PUBLIC ${catkin_LIBRARIES}${OpenCV_LIBS} ${vdo_slam_LIB_DIRS} # /home/tranks/testing_ws/src/VDO_SLAM/build/libvdo_slam.so ) I'm not saying it will solve your problem, but you're not linking correctly here. target_link_libraries(..) takes either a CMake target, or a (list of) absolute paths to libraries. You're passing it a directory (if the naming of vdo_slam_LIB_DIRS is correct). ( 2021-04-28 01:46:31 -0600 )edit @gvdhoorn Yes it should be ${vdo_slam_LIBRARIES} instead. I found that my current library is not linked to that libvdo_slam.so when I ran the $ldd or $readelf on the my library so file. Shouldn't it be linked since I already did target_link_libraries(... vdo_slam_LIBRARIES ...)?

( 2021-04-28 03:15:27 -0600 )edit

Sort by » oldest newest most voted

I got a solution here:

Eureka! I found a solution although it's not an ideal one. As mentioned in the question, I noticed that libvdo_slam.so was not listed as a shared library when running $readelf <on_my_library.so>. So I manually added -lvdo_slam in the CMakeList.txt so it looks like: target_link_libraries(ros_vdoslam_node${catkin_LIBRARIES}
${OpenCV_LIBS}${PROJECT_NAME}
-lvdo_slam
)  


Moreover, since "vdo_slam" also uses a modified "g2o" library, the same procedure had to be done in the VDO_SLAM library's CMakeList.txt(which is adding -lvdo_slam_g2o in a similar place).

Although it builds successfully now, I still wonder why this happened. From my understanding, -lvdo_slam is the same as \${vdo_slam_LIBS}, and the latter should be valid after using find_package(vdo_slam REQUIRED)`

more

3

( 2021-05-02 08:18:25 -0600 )edit

@gvdhoorn Thanks for the notice. Cheers

( 2021-05-02 10:39:10 -0600 )edit