Ask Your Question
0

[ROS2] custom message: Publisher typesupport error (build using conan)

asked 2020-07-06 08:51:47 -0600

Mavahu gravatar image

updated 2020-07-28 07:11:23 -0600

Hello, in the process of porting a part of a project to ROS 2 i got stuck at the following error:

conanfile.py (ros_trafficlightdetection/2.0.0): Running build()
Starting >>> ros_trafficlightdetection
CMakeFiles/ros_trafficlightdetection_node.dir/src/ros_trafficlightdetection_node.cpp.o: In function 
`rclcpp::Publisher<messages::msg::Gps_<std::allocator<void> >, std::allocator<void> 
>::Publisher(rclcpp::node_interfaces::NodeBaseInterface*, std::__cxx11::basic_string<char, std::char_traits<char>, 
std::allocator<char> > const&, rclcpp::QoS const&, rclcpp::PublisherOptionsWithAllocator<std::allocator<void> > const&)':
ros_trafficlightdetection_node.cpp: (.text._ZN6rclcpp9PublisherIN8messages3msg4Gps_ISaIvEEES4_EC2EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3QoSERKNS_29PublisherOptionsWithAllocatorIS4_EE[_ZN6rclcpp9PublisherIN8messages3msg4Gps_ISaIvEEES4_EC5EPNS_15node_interfaces17NodeBaseInterfaceERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_3QoSERKNS_29PublisherOptionsWithAllocatorIS4_EE]+0x6a): undefined reference to `rosidl_message_type_support_t const* rosidl_typesupport_cpp::get_message_type_support_handle<messages::msg::Gps_<std::allocator<void> > >()'
collect2: error: ld returned 1 exit status
make[2]: *** [ros_trafficlightdetection_node] Error 1
make[1]: *** [CMakeFiles/ros_trafficlightdetection_node.dir/all] Error 2
make: *** [all] Error 2
---
Failed   <<< ros_trafficlightdetection [1.92s, exited with code 2]

The project gets build via conan which we use for dependency managment. In ROS 1 it was working perfectly, but when following the official migration guide, i must have overlooked something.

This is the code used to build the package (while trying to fix the error i added a lot of dependencies to ament):

messages-package CMAKE:

cmake_minimum_required(VERSION 3.14)
project(messages)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(std_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(rosidl_typesupport_cpp REQUIRED)

set(msg_files 
    "msg/BurstMode.msg"
    "msg/CanGps.msg"
    "msg/CanMessage.msg"
    "msg/CanSignal.msg"
    "msg/CompressedData.msg"
    "msg/ElasticsearchInput.msg"
    "msg/FakeCam.msg"
    "msg/Gps.msg"
    "msg/ImageGps.msg"
    "msg/Metadata.msg"
    "msg/Request.msg"
    "msg/UsbCamRaw.msg"
)

rosidl_generate_interfaces(${PROJECT_NAME}
   ${msg_files}
   DEPENDENCIES std_msgs sensor_msgs builtin_interfaces rosidl_typesupport_cpp
)

ament_package()

ros_trafficlightdetection CMAKE:

cmake_minimum_required(VERSION 3.14)
include(${CMAKE_SOURCE_DIR}/../../conanbuildinfo.cmake)

set (PROJECT ${CONAN_PACKAGE_NAME})

project(${PROJECT})

cmake_policy(SET CMP0002 NEW)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0022 NEW)
cmake_policy(SET CMP0037 NEW)

message(${CONAN_PACKAGE_NAME} VERSION ${CONAN_PACKAGE_VERSION})
message(STATUS "Building Product: ${PROJECT_NAME} v${PROJECT_VERSION}")

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  message("set compiler")
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  message("added options")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()


include_directories(
  include
  SYSTEM
  ${CONAN_INCLUDE_DIRS}
)

## Die ROS Pakete, von denen das Paket abhängt
find_package(OpenCV REQUIRED)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(builtin_interfaces REQUIRED)
find_package(rosidl_typesupport_cpp REQUIRED)
find_package(rosidl_default_generators REQUIRED)

## Setup Funktion. Falls Python Skripte enthalten sind
#catkin_python_setup()

###################################
## ament_cmake specific configuration ##
###################################

ament_export_include_directories(
  include
  SYSTEM
  ${CONAN_INCLUDE_DIRS}
)
ament_export_dependencies(
  message_runtime
)

###########
## Build ##
###########s

CONAN_BASIC_SETUP(NO_OUTPUT_DIRS)

## Ausführbare Datei Deklarieren
add_executable(${PROJECT}_node ${CMAKE_SOURCE_DIR}/src/ros_trafficlightdetection_node.cpp)

## Die Bibliotheken werden mit der Ausführbaren Datei verlinkt
ament_target_dependencies(${PROJECT}_node 
  rclcpp
  rclpy
  std_msgs 
  sensor_msgs
  cv_bridge 
  image_transport
  rosidl_typesupport_cpp
  builtin_interfaces
)

target_link_libraries(${PROJECT}_node ${CONAN_LIBS})
target_link_libraries(${PROJECT}_node ${OpenCV_LIBRARIES})

install(TARGETS 
  ${PROJECT}_node
)

ament_package()

ros_trafficlightdetection cpp :

#include "ros_trafficlightdetection/ros_trafficlightdetection_node.h"

std::string diasutil::NODENAME;

  // Callback for GPS Message
void handleIncomingGpsMessage(messages::msg::Gps::ConstSharedPtr message) {
    lastGps = *message;
}

void handleIncomingImgMessage(const sensor_msgs::msg::Image::ConstSharedPtr& img, rclcpp::Publisher<messages::msg::UsbCamRaw>::SharedPtr &pub, Trafficlightdetection instance) {
  //RCLCPP_INFO(pub->get_logger(),"got image");
  cv_bridge::CvImagePtr cvPtr = cv_bridge ...
(more)
edit retag flag offensive close merge delete

Comments

I've in-lined your pastebins, as off-site resources have a tendency to disappear which will make this question difficult to understand in the future.

gvdhoorn gravatar image gvdhoorn  ( 2020-07-07 03:06:34 -0600 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2020-07-10 07:41:07 -0600

Mavahu gravatar image

Solution:
The solution in my case was that the command CONAN_BASIC_SETUP(NO_OUTPUT_DIRS) had to be called before the find_package() calls, looks like that in transition to ROS1 it is needed to do it before anything.

The final ros_trafficlightdetection CMakeLists.txt:

cmake_minimum_required(VERSION 3.14)
include(${CMAKE_SOURCE_DIR}/../../conanbuildinfo.cmake)

set (PROJECT ${CONAN_PACKAGE_NAME})

project(${PROJECT})

cmake_policy(SET CMP0002 NEW)
cmake_policy(SET CMP0003 NEW)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0022 NEW)
cmake_policy(SET CMP0037 NEW)

message(${CONAN_PACKAGE_NAME} VERSION ${CONAN_PACKAGE_VERSION})
message(STATUS "Building Product: ${PROJECT_NAME} v${PROJECT_VERSION}")

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

CONAN_BASIC_SETUP(NO_OUTPUT_DIRS)

## Die ROS Pakete, von denen das Paket abhängt
find_package(ament_cmake REQUIRED)
find_package(OpenCV REQUIRED)
find_package(std_msgs)
find_package(rclcpp REQUIRED)
find_package(rclpy REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(cv_bridge REQUIRED)
find_package(image_transport REQUIRED)
find_package(messages REQUIRED)


include_directories(
  include
  SYSTEM
  ${CONAN_INCLUDE_DIRS}
  ${ament_cmake_INCLUDE_DIRS}
 }


## Ausführbare Datei Deklarieren
add_executable(${PROJECT}_node ${CMAKE_SOURCE_DIR}/src/ros_trafficlightdetection_node.cpp)

## Die Bibliotheken werden mit der Ausführbaren Datei verlinkt
ament_target_dependencies(${PROJECT}_node 
  rclcpp 
  std_msgs 
  sensor_msgs 
  cv_bridge 
  image_transport 
  messages
)

ament_export_dependencies(message_runtime)
ament_export_include_directories(include)

target_link_libraries(${PROJECT}_node ${CONAN_LIBS})
target_link_libraries(${PROJECT}_node ${OpenCV_LIBRARIES})

install(TARGETS
  ${PROJECT}_node
  DESTINATION lib/${PROJECT}
)

ament_package()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-06 08:51:01 -0600

Seen: 371 times

Last updated: Jul 28 '20