0
$\begingroup$

Rosanswers logo

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!


Originally posted by lewis_ferreira on ROS Answers with karma: 3 on 2020-05-04

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by mgruhler with karma: 12390 on 2020-05-05

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by lewis_ferreira on 2020-05-05:
Thank you! Clear and straight forward explanation!

Comment by mgruhler on 2020-05-05:
happy to help!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.