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

Linking problem with rosidl cpp

asked 2018-04-04 10:06:33 -0500

kutschkem gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

Comments

Have you tried to build the two package (matrix2_msgs and matrix2_ros) in a normal workspace without the ExternalProject? If no, you might want to try that first. If yes, maybe sharing the code will allow others to comment / provide feedback.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-04-04 11:06:59 -0500 )edit

@Dirk Thomas I see a similar problem happened when you tried to build code related to this issue https://github.com/ros2/rclcpp/issues... , did you ever figure out what caused that linking problem?

kutschkem gravatar image kutschkem  ( 2018-04-05 01:56:52 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-04-05 03:04:49 -0500

kutschkem gravatar image

The problem here was that matrix2_msgs was not being linked into matrix2_ros. Since the compiler generates an actual instance of the template method, it is not found in rmw_fastrtps_cpp (which defines the template), but instead in matrix2_msgs__rosidl_typesupport_cpp (which instantiates the template).

I solved it by explicitely telling cmake where to look for that library, since ament didn't pick it up as the necessary environment variables are not set after generation.

add_library(matrix2_msgs_imported SHARED IMPORTED)
set_target_properties(matrix2_msgs_imported PROPERTIES
    IMPORTED_LOCATION "${ros_msg_dir}/libmatrix2_msgs__rosidl_typesupport_cpp.so"
)
target_link_libraries(${PROJECT_NAME} matrix2_msgs_imported)

Lesson learned: When looking at linking errors involving templates, think hard about where that symbol is actually generated.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2018-04-04 10:06:33 -0500

Seen: 1,347 times

Last updated: Apr 05 '18