Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ headers generated at build time with rosidl CLI #686

Open
terrakuh opened this issue Jul 5, 2022 · 2 comments
Open

C++ headers generated at build time with rosidl CLI #686

terrakuh opened this issue Jul 5, 2022 · 2 comments
Labels

Comments

@terrakuh
Copy link

terrakuh commented Jul 5, 2022

Question

Is it possible to compile at build time generated IDL-files using rosidl_cli to C++ headers and build a ROS service node with that?

Setup

  • OS: Ubuntu 22.04
  • Compiler: GCC 12
  • CMake: 3.22

CMakeLists.txt

cmake_minimum_required(VERSION 3.20)

project(test)

find_package(rclcpp REQUIRED)
add_executable(my-test main.cpp my_service/srv/test__type_support.cpp)
target_link_libraries(my-test rclcpp::rclcpp)
target_include_directories(my-test PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")

main.cpp

#include <rclcpp/rclcpp.hpp>

#include "my_service/srv/test.hpp"

inline void test(const std::shared_ptr<my_service::srv::Test::Request> request,
                              std::shared_ptr<my_service::srv::Test::Response> response)
{
  puts("Just a test.");
}


int main(int argc, char** argv)
{
  rclcpp::init(argc, argv);
  const auto node = rclcpp::Node::make_shared("test");

  const auto service_grip = node->create_service<my_service::srv::Test>("test", &test);

  std::cout << "ROS2 node up and running\n";
  rclcpp::spin(node);
  rclcpp::shutdown();
}

srv/Test.srv

string msg
---
string reply

My project structure is also attached here: test.tar.gz

Steps

Where the files reside I execute the following:

rosidl generate --type cpp --type-support cpp my_service srv/Test.srv
mv cpp my_service
cmake -S . -B build
cmake --build build
./build/my-test

Output:

terminate called after throwing an instance of 'rclcpp::exceptions::RCLError'
  what():  could not create service: Type support not from this implementation. Got:
    Handle's typesupport identifier (rosidl_typesupport_cpp) is not supported by this library, at ./src/type_support_dispatch.hpp:111
    Could not load library libmy_service__rosidl_typesupport_fastrtps_cpp.so: dlopen error: libmy_service__rosidl_typesupport_fastrtps_cpp.so: cannot open shared object file: No such file or directory, at ./src/shared_library.c:99, at ./src/type_support_dispatch.hpp:76
while fetching it, at ./src/rmw_service.cpp:125, at ./src/rcl/service.c:124
Aborted (core dumped)
@Rodario
Copy link

Rodario commented Jul 19, 2022

I also wondered about this. Would the cmake be the correct place for that tho? It would be pretty nice to just have a cmake function that compiles your srv / msg file and links the result to your project.

@clalancette
Copy link
Contributor

There is a design PR opened about this topic: ros2/design#310 . While we did expose some parts of the rosidl pipeline to the command-line, I don't believe we ever implemented all of the bits necessary to do what you'd like to do.

So this is future work. That said, if you use the normal CMake mechanisms for packages and messages (like in https://docs.ros.org/en/rolling/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html), CMake should take care of all of this for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants