ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Undefined reference error despite linking the library [closed]

asked 2014-10-16 17:38:14 -0600

mhariharasudan gravatar image

updated 2014-10-16 17:39:16 -0600

Hi,

I am using ROS Hydro on Ubuntu 12.04. I have a package named as libbarrett_ros. The declaration of the class arm_interface is in include/barrett_arm.h and the definition is in src/barrett_arm.cpp. The executable node (src/libbarrett_ros.cpp) creates an instance of the class barrett_arm_interface in its main function.

However, catkin_make returns the following error for me,

Linking CXX executable /home/robot/catkin_ws/devel/lib/libbarrett_ros/libbarrett_ros
CMakeFiles/libbarrett_ros.dir/src/libbarrett_ros.cpp.o: In function `int wam_main<3u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3u>&)':
libbarrett_ros.cpp:(.text._Z8wam_mainILj3EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE[int wam_main<3u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<3u>&)]+0x14): undefined reference to `barrett_arm_interface<3u>::barrett_arm_interface()'
CMakeFiles/libbarrett_ros.dir/src/libbarrett_ros.cpp.o: In function `int wam_main<4u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<4u>&)':
libbarrett_ros.cpp:(.text._Z8wam_mainILj4EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE[int wam_main<4u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<4u>&)]+0x14): undefined reference to `barrett_arm_interface<4u>::barrett_arm_interface()'
CMakeFiles/libbarrett_ros.dir/src/libbarrett_ros.cpp.o: In function `int wam_main<7u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<7u>&)':
libbarrett_ros.cpp:(.text._Z8wam_mainILj7EEiiPPcRN7barrett14ProductManagerERNS2_7systems3WamIXT_EEE[int wam_main<7u>(int, char**, barrett::ProductManager&, barrett::systems::Wam<7u>&)]+0x14): undefined reference to `barrett_arm_interface<7u>::barrett_arm_interface()'
collect2: ld returned 1 exit status
make[2]: *** [/home/robot/catkin_ws/devel/lib/libbarrett_ros/libbarrett_ros] Error 1
make[1]: *** [libbarrett_ros/CMakeFiles/libbarrett_ros.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed

I know that this is a problem with linking the barrett_arm with my executable node. I have added the barrett_arm.cpp and linked the target against my executable node. But that does not solve the problem either. Please let me know what I am missing here. Thanks in advance.

My CMakeLists.txt is as below

cmake_minimum_required(VERSION 2.8.3)
project(libbarrett_ros)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  message_generation
)

find_package(Barrett REQUIRED)
find_package(Eigen REQUIRED)

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS 
  message_runtime
  wam_msgs
  LIBRARIES ${PROJECT_NAME}
)

include_directories(include
  ${catkin_INCLUDE_DIRS}
)
link_directories(${BARRETT_LIB_DIRS})
include_directories(${BARRETT_INCLUDE_DIRS})
add_definitions(${BARRETT_DEFINITIONS})

add_library(barrett_arm src/barrett_arm.cpp)
target_link_libraries(barrett_arm ${catkin_LIBRARIES} ${BARRETT_LIBRARIES})

add_executable(${PROJECT_NAME} src/libbarrett_ros.cpp)
target_link_libraries(${PROJECT_NAME} barrett_arm ${catkin_LIBRARIES} ${BARRETT_LIBRARIES})

add_dependencies(${PROJECT_NAME} ${catkin_EXPORTED_TARGETS} wam_msgs_gencpp)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by mhariharasudan
close date 2014-10-17 09:18:13.459814

Comments

The barrett_arm_interface class looks like a template class, and it looks like you're failing to link against a specific instantiation of that template. Is that class part of your library or part of the barret library you're linking to?

ahendrix gravatar image ahendrix  ( 2014-10-16 17:48:38 -0600 )edit

Yes, the barrett_arm_interface class is a template class. This is part of my library. I have written my own template class that gets instantiated with the DOF value which is 3u, 4u and 7u passed from libbarrett_ros.cpp.

mhariharasudan gravatar image mhariharasudan  ( 2014-10-16 19:35:58 -0600 )edit

Initially, I had barrett_arm_interface template class defined and declared within libbarrett_ros.cpp. And in the main function I was creating an instance of it and initializing the class as now. It all worked fine. But now when I moved that class as a separate source file, I am facing this problem

mhariharasudan gravatar image mhariharasudan  ( 2014-10-16 19:38:15 -0600 )edit

Thank you so much. You saved my day, I didnt think anything beyond "catkin linking error".

mhariharasudan gravatar image mhariharasudan  ( 2014-10-17 09:17:58 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-10-16 19:57:32 -0600

ahendrix gravatar image

updated 2014-10-17 11:46:02 -0600

Unless you're creating template specializations, your template class should be implemented completely in your header file. See: http://stackoverflow.com/questions/49...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-10-16 17:38:14 -0600

Seen: 2,264 times

Last updated: Oct 17 '14