I am migrating from conan1 to conan2. Unfortunately my ROS node which depends on a custom IDL message interface is not built successfully anymore in conan2. The linking stage fails with:
undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<ros2_custom_message_interface::msg::CustomMessage_<std::allocator<void> > >()'`
Using a combination of grep
and find
I tracked down that rosidl_message_type_support_t const
is defined in the file /opt/ros/humble/include/rosidl_runtime_c/rosidl_runtime_c/message_type_support_struct.h
How can I get cmake
to take the file into account? I tried adding rosidl_runtime_c
in find_package
, ament_target_dependencies
and target_link_libraries
options without success.
Note: Before I execute the build with conan, I am sourcing the ROS environment in my terminal.
My CMakeLists.txt
file is:
cmake_minimum_required(VERSION 3.5)
project(ros2_custom_message_node)
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
set(TARGET_NAME custom_message_node)
add_executable(${TARGET_NAME} src/main.cpp)
install(TARGETS ${TARGET_NAME})
# Parts that are more specific to ROS 2.
find_package(ament_cmake_auto REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_components REQUIRED)
ament_auto_find_build_dependencies()
ament_target_dependencies(${TARGET_NAME} rclcpp ros2_custom_message_interface)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()
endif()
# export dependencies correctly
ament_auto_package()
and my conanfile.py
is
from conan import ConanFile
from conan.tools.cmake import CMake
class Ros2CustomMessageNode(ConanFile):
name = "ros2_custom_message_node"
version = "0.1.0"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeToolchain", "CMakeDeps"
exports_sources = "CMakeLists.txt", "package.xml", "src/*"
def requirements(self):
self.requires("ros2_custom_message_interface/0.1.0")
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.install()