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

Build C++ Library and use in Python Package (Node)

asked 2020-10-08 06:12:45 -0600

Deniz gravatar image

Dear ROS(2) community,

I have developed a C++ library that exposes it's classes to python using Pybind11 bindings. As a dry-run I managed to get the python node to work with the C++ classes. Thus I am able to use this C++ library in a python node.

However, this only works if I manually build the C++ library externally and copy-paste the shared library (.so) into the ROS build folder of my python package.

Obviously this should not be the final way of doing this.

So my question is this:

  1. Is it possible to nest my C++ library into the python package
  2. Build the C++ library && Build the python package <-- in one colcon build --symlink-install command
  3. Run the python package with python knowing where to look for the built library

basically, seamless integration of my C++ library in my python node

Greetings and thank you for your time,

Deniz

edit retag flag offensive close merge delete

Comments

My intuition is telling me that i should wrap this as a whole as a C++ package (and not as a python package)...

Deniz gravatar image Deniz  ( 2020-10-08 06:26:08 -0600 )edit

If you make it a c++ package, you can't (to the best of my knowledge) make endpoints to the python code which means you can't run it via ros2 run .... Similarly, with a python package you can't build the c++ code.

Per Edwardsson gravatar image Per Edwardsson  ( 2022-07-26 06:04:41 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-09-21 17:38:53 -0600

kc gravatar image

Here's s solution I've been working on. You'll have to tweak this pkg to your requirements. Link to pkg: https://github.com/KC-git-usr/pybind1... Refence I used: https://answers.ros.org/question/3621...

edit flag offensive delete link more

Comments

Thanks dude

chrissunny94 gravatar image chrissunny94  ( 2023-08-03 01:13:32 -0600 )edit
0

answered 2022-07-26 06:03:00 -0600

Per Edwardsson gravatar image

You can't mix source code languages in one ament package. I would make two packages of it and allow ament to solve dependencies. As an alternative, build the c++ lib statically and place it in the python package as a data file.

Or, tell ament how to deal with your mixed package. You can have a look at https://github.com/colcon/colcon-meson or related for an example on how to extend colcon. But I get the feeling that this is more of a one-off type situation.

edit flag offensive delete link more

Comments

It IS possible to mix C++ and Python in a single colcon package and build by colcon. E.g. https://answers.ros.org/question/309391

130s gravatar image 130s  ( 2023-04-07 02:20:12 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2020-10-08 06:12:45 -0600

Seen: 940 times

Last updated: Jul 26 '22