Ask Your Question

Weird "Undefined Reference ..." error despite using target link libraries.

asked 2017-05-30 20:09:24 -0600

yzheng0310 gravatar image

updated 2017-12-19 22:05:41 -0600

ngrennan gravatar image

Hi Every one,

I'm using ROS Hydro on Ubuntu 12.04,

In one of my code I'm using a BIoTacHand class from the biotac ros driver, the class header file is in the biotac_sensors package. So basically, I have three biotac fingers attached to a barrett wam arm, and I aim to collect the biotac data while moving the wam, so I initialized a BioTacHand class in my wam running code as the following:

using namespace barrett;
using detail::waitForEnter;
using namespace biotac;
//ProductManager PM("/etc/barrett/bus1/default.conf");
//Global parameters for BioTacHandClass
biotac::BioTacHandClass LEFT_HAND("left_hand"); //initialize the biotac hand class

The code used to work fine, however this afternoon when I changed some other parts in the code and recompiled, the compiler threw out the following error:

Linking CXX executable /home/robot/yzheng_ws/devel/lib/wam_node/wam_node_l
CMakeFiles/wam_node_l.dir/src/wam_node_l.cpp.o: In function `__static_initialization_and_destruction_0':
/home/robot/yzheng_ws/src/wam_robot/wam_node/src/wam_node_l.cpp:116: undefined reference to   `biotac::BioTacHandClass::BioTacHandClass(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/home/robot/yzheng_ws/src/wam_robot/wam_node/src/wam_node_l.cpp:116: undefined reference to `biotac::BioTacHandClass::~BioTacHandClass()'
collect2: ld returned 1 exit status 
make[2]: *** [/home/robot/yzheng_ws/devel/lib/wam_node/wam_node_l] Error 1   
make[1]: *** [wam_robot/wam_node/CMakeFiles/wam_node_l.dir/all] Error 2
make: *** [all] Error 2

However, I've added the biotac_sensors package as a catkin component, as used target_link_libraries tags, here is my CMakelist for the wam_node package:

cmake_minimum_required(VERSION 2.8.3)
find_package(catkin REQUIRED COMPONENTS std_msgs std_srvs sensor_msgs geometry_msgs trajectory_msgs roscpp roslib tf wam_msgs rosbag biotac_sensors cheetah_lib)
CATKIN_DEPENDS std_msgs std_srvs sensor_msgs geometry_msgs trajectory_msgs roscpp tf wam_msgs roslib rosbag biotac_sensors cheetah_lib


find_package(Barrett REQUIRED)
link_directories(${BARRETT_LIB_DIRS} src)

add_executable(wam_node_l src/wam_node_l.cpp)
target_link_libraries(wam_node_l ${catkin_LIBRARIES} ${BARRETT_LIBRARIES})
add_dependencies(wam_node_l ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS}     wam_msgs_gencpp)

and here is the gist of package.xml of the wam_node package:



Does any one have any idea ? The answer I found after searching through are all about missing the target_link_libraries tag, also the BioHandClass IS NOT A TEMPLATE CLASS. Thx!

EDIT: The change I made to the CMakeLists.txt of the wam_node package:

 add_executable(wam_node_l src/wam_node_l.cpp) 
 target_link_libraries(wam_node_l ${catkin_LIBRARIES} ${BARRETT_LIBRARIES} biotacpub)
 add_dependencies(wam_node_l ${catkin_EXPORTED_TARGETS} ${${PROJECT_NAME}_EXPORTED_TARGETS} wam_msgs_gencpp)

EDIT: The CMakeLists.txt for the biotac_sensors package I'm using is the following:

  cmake_minimum_required(VERSION 2.8.3)

  find_package(catkin REQUIRED COMPONENTS roscpp cheetah_lib message_generation std_msgs)

  include_directories ...
edit retag flag offensive close merge delete


Did you include the biotac_sensors/biotac_hand_class.h?

DavidN gravatar image DavidN  ( 2017-05-31 00:50:23 -0600 )edit

Hi DavidN, Yes I did that, here is a snapshot of the code: 43 #include <biotac_sensors/biotac_hand_class.h>44 #include <biotac_sensors/BioTacHand.h>

yzheng0310 gravatar image yzheng0310  ( 2017-05-31 01:25:00 -0600 )edit

Can you try to add biotac_sensor to the target_link_libraries so that you will have something like this: target_link_libraries(wam_node_l ${catkin_LIBRARIES} ${BARRETT_LIBRARIES} biotac_sensor)

DavidN gravatar image DavidN  ( 2017-05-31 01:52:09 -0600 )edit

HI DavidN, thanks for the replay. Instead of biotac_sensors, I added the library generated in biotac_sensors, called biotacpub to the target_link_libraries and it compiled successfully. You I can see the change I made in the edited question.

yzheng0310 gravatar image yzheng0310  ( 2017-05-31 13:15:55 -0600 )edit

Since I exported the biotacpub library of biotac_sensors package using catkin_package(). Then if I added the biotac_sensors package as a catkin component in wam_node package, wouldn't ${catkin_LIBRARIES} include everything from biotac_sensors ?

yzheng0310 gravatar image yzheng0310  ( 2017-05-31 13:22:08 -0600 )edit

If biotac_sensors package exported biotac_sensor library, it is enough to use ${catkin_LIBRARIES}. However, it seems biotac_sensors package did not use catkin_package() to export the library.

Haibo gravatar image Haibo  ( 2017-06-01 09:42:50 -0600 )edit

It is great that you found the solution. Please post the actual solution as the answer and close this question. :)

DavidN gravatar image DavidN  ( 2017-06-01 11:32:12 -0600 )edit

Hi Haibo, I double checked the CMakeLIsts.txt file in biotac_sensors, it did use catkin_package( DEPENDS CATKIN_DEPENDS message_runtime roscpp cheetah_lib std_msgs INCLUDE_DIRS include LIBRARIES biotacpub )

yzheng0310 gravatar image yzheng0310  ( 2017-06-01 11:43:49 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2017-06-01 11:44:48 -0600

yzheng0310 gravatar image

Problem solved, see the edit I made! However I still don't understand why this error would happen, everything seems normal.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-05-30 20:07:05 -0600

Seen: 5,683 times

Last updated: Jun 01 '17