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

Catkin build fails to find reference to library inside the same package

asked 2020-05-04 18:28:23 -0600

lewis_ferreira gravatar image

updated 2020-05-04 19:23:05 -0600

Hi to all! first of all, english is not my native language :D I'm sorry if there are too many mistakes, here we go.

I decided to add a library master_utils inside the package master_core to add some extended functions to some msg types created inside the package. I followed the docs to add/install the library with the rest of the package.

The strange situation that I'm going through is:

  • When calling a function defined in master_utils from another package (adding master_core as dependecy and #include <master_core/master_utils.h>) it builds with no error and has the expected result.
  • When calling the same function defined in master_utils on the file RSI_parser.cpp (both inside the same package master_core) I get a build error.

The error catkin build throws is:

/home/lewis/master/mestrado/src/ROS/catkin_ws/src/master_core/src/controller/RSI_parser.cpp:37: error: undefined reference to `stampedTFtoKukaPose(tf::StampedTransform&, master_core::KukaPose_<std::allocator<void> >&)'

I found this post that is closely related to my problem, but didn't find anything related to the solution on the docs page I was following. Maybe that points that the problem is more related to CMakeLists than to ROS.

I don't know if it's related, but when adding the #include on .cpp files, all of the generated headers are duplicated on QT auto completion, except master_utils.

The package structure and files are as the following:

package structure:

master_core
-include
  -master_core
    -master_utils.h
-src
  -master_utils.cpp
  -controller
    -RSI_parser.cpp

CMakeLists.txt (Omitting some add_executable/add_dependencies/target_link_libraries from other nodes)

cmake_minimum_required(VERSION 2.8.3)
project(master_core)

add_compile_options(-std=c++11)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  message_generation
  geometry_msgs
  tf
  master_moveit
  moveit_ros_planning_interface
  urdf
)

add_message_files(
  FILES
  RobotAxis.msg
  KukaPose.msg
  RSI.msg
)

generate_messages(
  DEPENDENCIES
  std_msgs  # Or other packages containing msgs
  geometry_msgs
  moveit_msgs
)

catkin_package(
  INCLUDE_DIRS include
  LIBRARIES master_utils
  CATKIN_DEPENDS roscpp
  message_runtime
)

include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

add_library(master_utils src/master_utils.cpp)
add_dependencies(master_utils ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(master_utils ${catkin_LIBRARIES})

add_executable(RSI_node src/controller/RSI_parser.cpp)
add_dependencies(RSI_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(RSI_node ${catkin_LIBRARIES})

install(TARGETS master_utils
   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
 )

 install(DIRECTORY include/${PROJECT_NAME}/
   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
 )

master_utils.h

#ifndef MASTER_UTILS_H
#define MASTER_UTILS_H

#include <ros/ros.h>
#include <master_core/KukaPose.h>
#include <master_core/RSI.h>
#include <master_core/RobotAxis.h>
#include <tf/tf.h>

void stampedTFtoKukaPose(tf::StampedTransform&, master_core::KukaPose&);

#endif

RSI_parser.cpp

...
#include <master_core/master_utils.h>
...

...
void sendRSI() {
...
tf::StampedTransform ref_to_RIst;
master_core::KukaPose RIst;
stampedTFtoKukaPose(ref_to_RIst, RIst);
...
}

I think maybe I left a configuration out of CMakeLists.txt, or am missing a concept about the compiler. (The probability is high, as I'm no C++ expert)

Do I have to develop libraries on a separate package or is it possible to develop it as extension from the same package as I'm trying to do?

Thank you very much for your attention!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-05-05 01:06:19 -0600

mgruhler gravatar image

What you got here is a linker error. The compiler cannot resolve, in the RSI_parser.cpp, where the function stampedTFtoKukaPose is implemented. After all, you only have the declaration included.

You need to tell CMake to link your executable against the library containing the implementation. I.e.

target_link_libraries(RSI_node master_utils ${catkin_LIBRARIES})

This must be done explicitly if the library is built in the same package, as the catkin_LIBRARIES variables only captures the libraries that are find_package'd.

edit flag offensive delete link more

Comments

Thank you! Clear and straight forward explanation!

lewis_ferreira gravatar image lewis_ferreira  ( 2020-05-05 06:42:24 -0600 )edit

happy to help!

mgruhler gravatar image mgruhler  ( 2020-05-05 08:20:34 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2020-05-04 18:28:23 -0600

Seen: 422 times

Last updated: May 05 '20