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:
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.
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 ...
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?
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
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).@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 didtarget_link_libraries(... vdo_slam_LIBRARIES ...)
?