Weird "Undefined Reference ..." error despite using target link libraries.
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)
project(wam_node)
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_package(
DEPENDS Barrett
CATKIN_DEPENDS std_msgs std_srvs sensor_msgs geometry_msgs trajectory_msgs roscpp tf wam_msgs roslib rosbag biotac_sensors cheetah_lib
INCLUDE_DIRS
LIBRARIES
)
include_directories(include
${catkin_INCLUDE_DIRS}
)
find_package(Barrett REQUIRED)
link_directories(${BARRETT_LIB_DIRS} src)
include_directories(${BARRETT_INCLUDE_DIRS})
add_definitions(${BARRETT_DEFINITIONS})
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:
<build_depend>std_msgs</build_depend>
<build_depend>std_srvs</build_depend>
<build_depend>sensor_msgs</build_depend>
<build_depend>geometry_msgs</build_depend>
<build_depend>trajectory_msgs</build_depend>
<build_depend>roscpp</build_depend>
<build_depend>roslib</build_depend>
<build_depend>bullet</build_depend>
<build_depend>tf</build_depend>
<build_depend>wam_msgs</build_depend>
<build_depend>wam_srvs</build_depend>
<build_depend>rosbag</build_depend>
<build_depend>biotac_sensors</build_depend>
<build_depend>cheetah_lib</build_depend>
<run_depend>std_msgs</run_depend>
<run_depend>std_srvs</run_depend>
<run_depend>sensor_msgs</run_depend>
<run_depend>geometry_msgs</run_depend>
<run_depend>trajectory_msgs</run_depend>
<run_depend>roscpp</run_depend>
<run_depend>roslib</run_depend>
<run_depend>bullet</run_depend>
<run_depend>tf</run_depend>
<run_depend>wam_msgs</run_depend>
<run_depend>wam_srvs</run_depend>
<run_depend>rosbag</run_depend>
<run_depend>biotac_sensors</run_depend>
<run_depend>cheetah_lib</run_depend>
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)
project(biotac_sensors)`
find_package(catkin REQUIRED COMPONENTS roscpp cheetah_lib message_generation std_msgs)
include_directories ...
Did you include the
biotac_sensors/biotac_hand_class.h
?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>
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)
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.
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 ?If
biotac_sensors
package exportedbiotac_sensor
library, it is enough to use${catkin_LIBRARIES}
. However, it seemsbiotac_sensors
package did not usecatkin_package()
to export the library.It is great that you found the solution. Please post the actual solution as the answer and close this question. :)
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 )