Create a Python module with pybind11 and use it in another package
I'm trying to build a Python module with pybind11 in package pkg1 and use it from package pkg2. Is there any example of how to do this?
I tried the following:
ros2 pkg create pkg1
- Add the following to pkg1's CMakeLists.txt:
_
find_package(pybind11 REQUIRED)
pybind11_add_module(pkg1 src/example.cpp)
install(
TARGETS pkg1
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
Building this package creates pkg1.cpython-38-x86_64-linux-gnu.so
in install/pkg1/lib
.
Then I created pkg2:
ros2 pkg create --build-type ament_python --node-name pkg2_demo pkg2
To its package.xml
I added <depend>pkg1</depend>
. However, I know that a few steps are missing until I can call import pkg1
from a Python script in pkg2. Can anyone help?