Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Linking problem with rosidl cpp

The following is my CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(matrix2_ros)


## generate messages
include (ExternalProject)
ExternalProject_Add(matrix2_msgs
SOURCE_DIR "${ros_impl_dir}"
INSTALL_COMMAND ""
)

ExternalProject_Get_Property(matrix2_msgs BINARY_DIR)
set(ros_msg_dir ${BINARY_DIR})
##

if(NOT WIN32)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Wpedantic")
endif()

find_package(ament_cmake_ros REQUIRED)
find_package(example_interfaces REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcutils)
find_package(rmw REQUIRED)

set(ros_algo_hdr
  "include/rosBinding.h"
)

set(ros_algo_src
    "src/main.cpp"

)

    set(ros_protobuf

    "protobuf/Test/Mat.msg2structs.h"
    "protobuf/Test/Mat.msg2structs.cc"
    "protobuf/Test/Mat.structs2msg.h"
    "protobuf/Test/Mat.structs2msg.cc"
    )


add_executable(${PROJECT_NAME} ${ros_algo_hdr} ${ros_algo_src} ${ros_protobuf})

add_dependencies(${PROJECT_NAME} matrix2_msgs)

 target_link_libraries(${PROJECT_NAME} ${MODULE_NAME}_core)

ament_target_dependencies(${PROJECT_NAME}
    "rclcpp"
    "rcutils"
    "matrix2_msgs")
  install(TARGETS ${PROJECT_NAME}
  DESTINATION lib/${PROJECT_NAME})


    # handle library dependencies   
    if(MSVC)
        find_package(OpenCV REQUIRED core highgui imgproc)
        include_directories("${OPENCV_INCLUDE_DIRS}") 
        message(STATUS "OpenCV win include dir: ${OPENCV_INCLUDE_DIRS}") 
        target_link_libraries(${PROJECT_NAME} ${OpenCV_LIB_CORE} ${OpenCV_LIB_HIGHGUI} ${OpenCV_LIB_IMGPROC})
    else(MSVC)
        find_package(PkgConfig REQUIRED) 
        pkg_check_modules(OPENCV REQUIRED opencv)
        include_directories("${OPENCV_INCLUDE_DIRS}") 
        message(STATUS "OpenCV include dir: ${OPENCV_INCLUDE_DIRS}")
        # remove test lib which conflicts with GTest (see https://schneide.wordpress.com/2014/02/03/testing-c-code-with-opencv-dependencies/ 
        list(REMOVE_ITEM OPENCV_LIBRARIES opencv_ts)
        target_link_libraries(${PROJECT_NAME} ${OPENCV_LIBRARIES})
        message(STATUS "OpenCV included in ara project: ${OPENCV_LIBRARIES}")
    endif(MSVC)



    source_group("Autogen\\Header Files" FILES "${ros_algo_hdr}" )
    source_group("Autogen\\Source Files" FILES "${ros_algo_src}" )
    source_group("Autogen\\Protobuf\\Converters" FILES "${ros_protobuf}")

    target_include_directories(${PROJECT_NAME}
        PRIVATE "include/"
        PRIVATE "protobuf/"
        PRIVATE "${ros_msg_dir}/rosidl_generator_cpp/"
    )

ament_package()

And the package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://
www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>matrix2_ros</name>
  <version>0.1.0</version>
  <description>ROS binding for matrix2</description>
  <maintainer email="maintainer@example.com">FillMeIn</maintainer>
  <license></license>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <build_depend>rosidl_default_generators</build_depend>
  <build_depend>builtin_interfaces</build_depend>
  <exec_depend>builtin_interfaces</exec_depend>
  <build_depend>matrix2_msgs</build_depend>
  <exec_depend>matrix2_msgs</exec_depend>

  <build_depend>rclcpp</build_depend>
  <build_depend>rcutils</build_depend>
  <build_depend>rmw_implementation_cmake</build_depend>  

  <exec_depend>rclcpp</exec_depend>
  <exec_depend>rcutils</exec_depend>
  <exec_depend>rmw_implementation</exec_depend>
  <exec_depend>rosidl_default_runtime</exec_depend>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

The problem I am facing is that during the linking phase, some symbols are not found. Here is the output of make VERBOSE=1.

[ 82%] Linking CXX executable matrix2_ros
cd /home/uidq3479/Jenkins/workspace/XCitDevelopment_PR-164-OI7ZPASJZEV3XGQWBFQY2PEQXIELKYENI5G6JZQZXQR3CPC6F5NA/tests/eclipseProject/projects/math/build/cmake/algos/matrix/matrix2/ros && /usr/bin/cmake -E cmake_link_script CMakeFiles/matrix2_ros.dir/link.txt --verbose=1
/usr/bin/c++  -Wl,--no-as-needed -pthread -g -std=c++14 -Wall -std=c++14 -Wall -Wextra -Wpedantic   CMakeFiles/matrix2_ros.dir/src/main.cpp.o CMakeFiles/matrix2_ros.dir/protobuf/Test/Mat.msg2structs.cc.o CMakeFiles/matrix2_ros.dir/protobuf/Test/Mat.structs2msg.cc.o  -o matrix2_ros -Wl,-rpath,/usr/local/lib:/home/uidq3479/ros2-linux/lib: ../implementation/libmatrix2_core.a /home/uidq3479/ros2-linux/lib/librosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_generator_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_cpp.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_generator_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_introspection_cpp.so /usr/local/lib/libfastcdr.so /usr/local/lib/libfastrtps.so.1.5.0 /home/uidq3479/ros2-linux/lib/librmw.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_introspection_cpp.so /home/uidq3479/ros2-linux/lib/librmw_fastrtps_cpp.so /home/uidq3479/ros2-linux/lib/librcl.so /home/uidq3479/ros2-linux/lib/librosidl_generator_c.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/librclcpp.so /home/uidq3479/ros2-linux/lib/librcutils.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_generator_c.so /home/uidq3479/ros2-linux/lib/libbuiltin_interfaces__rosidl_typesupport_introspection_cpp.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_cpp.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_generator_c.so /home/uidq3479/ros2-linux/lib/librcl_interfaces__rosidl_typesupport_introspection_cpp.so /home/uidq3479/ros2-linux/lib/librmw.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_introspection_c.so /home/uidq3479/ros2-linux/lib/librosidl_typesupport_introspection_cpp.so /home/uidq3479/ros2-linux/lib/librmw_fastrtps_cpp.so /home/uidq3479/ros2-linux/lib/librcl.so /home/uidq3479/ros2-linux/lib/librosidl_generator_c.so /home/uidq3479/ros2-linux/lib/librclcpp.so /home/uidq3479/ros2-linux/lib/librcutils.so -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videostab -lpthread /usr/local/lib/libtinyxml2.a
CMakeFiles/matrix2_ros.dir/src/main.cpp.o: In Funktion `rclcpp::Publisher<matrix2_msgs::msg::mat_<std::allocator<void> >, std::allocator<void> >::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, rcl_publisher_options_t const&, std::shared_ptr<std::allocator<matrix2_msgs::msg::mat_<std::allocator<void> > > > const&)':
/home/uidq3479/ros2-linux/include/rclcpp/publisher.hpp:173: Nicht definierter Verweis auf `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<matrix2_msgs::msg::mat_<std::allocator<void> > >()'
CMakeFiles/matrix2_ros.dir/src/main.cpp.o: In Funktion `rclcpp::Subscription<matrix2_msgs::msg::mat_<std::allocator<void> >, std::allocator<void> >::Subscription(std::shared_ptr<rcl_node_t>, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, rcl_subscription_options_t const&, rclcpp::AnySubscriptionCallback<matrix2_msgs::msg::mat_<std::allocator<void> >, std::allocator<void> >, std::shared_ptr<rclcpp::message_memory_strategy::messagememorystrategy<matrix2_msgs::msg::mat_<std::allocator<void> >, std::allocator<void> > >)':
/home/uidq3479/ros2-linux/include/rclcpp/subscription.hpp:155: Nicht definierter Verweis auf `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<matrix2_msgs::msg::mat_<std::allocator<void> > >()'
collect2: error: ld returned 1 exit status
algos/matrix/matrix2/ros/CMakeFiles/matrix2_ros.dir/build.make:190: die Regel für Ziel âalgos/matrix/matrix2/ros/matrix2_rosâ scheiterte
make[2]: *** [algos/matrix/matrix2/ros/matrix2_ros] Fehler 1
make[2]: Verzeichnis â/home/uidq3479/Jenkins/workspace/XCitDevelopment_PR-164-OI7ZPASJZEV3XGQWBFQY2PEQXIELKYENI5G6JZQZXQR3CPC6F5NA/tests/eclipseProject/projects/math/build/cmakeâ wird verlassen
CMakeFiles/Makefile2:1268: die Regel für Ziel âalgos/matrix/matrix2/ros/CMakeFiles/matrix2_ros.dir/allâ scheiterte
make[1]: *** [algos/matrix/matrix2/ros/CMakeFiles/matrix2_ros.dir/all] Fehler 2

The most specific line seems to be

/home/uidq3479/ros2-linux/include/rclcpp/subscription.hpp:155: Undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle > >()'
I tried explicitly linking with rosidl_typesupport_cpp by including the following two lines in the CMake script, but it didn't help. Now I am stuck at trying to resolve that linking error and wonder whether I need to include something in the CMake script, the package.xml or both.
find_package(rosidl_typesupport_cpp REQUIRED)
target_link_libraries(${PROJECT_NAME} ${rosidl_typesupport_cpp_LIBRARIES})