Skip to content

Commit cffd12c

Browse files
author
Felix Widmaier
committed
Avoid the nasty 'lib'-prefix
By default library-names are automatically prefixed by 'lib'. In the ROS wiki I found a command to supress this :)
1 parent e253c47 commit cffd12c

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ add_library(mycpplib SHARED
5656
)
5757
# change output directory, so python can find the module
5858
set_target_properties(mycpplib PROPERTIES
59+
PREFIX ""
5960
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
6061
)
6162

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ Configure cmake
3535
${catkin_LIBRARIES}
3636
${Boost_LIBRARIES}
3737
)
38-
# change output directory, so python can find the module
38+
# change output directory, so python can find the module and avoid the 'lib'-prefix
3939
set_target_properties(mycpplib PROPERTIES
40+
PREFIX ""
4041
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
4142
)
4243
The last command is important because it will change the destination of the compiled library
@@ -54,11 +55,31 @@ After you compiled the package, you should be able to use the wrapped module in
5455
cpp.hello()
5556

5657

58+
Boost::Python and ROS::NodeHandle
59+
---------------------------------
60+
61+
When using ROS, there is one important thing to keep in mind: Assume you have a ROS node written
62+
in Python, that uses some C++ code via Boost::Python.
63+
If the C++ code needs a `ros::NodeHandle`, for example to fetch some parameters from the
64+
parameter server, it will crash, because the `rospy.init_node()' does **not** initialize roscpp!
65+
66+
To get around this, you need the _MoveIt ROS planning interface_ which is available in the ROS
67+
repos (`sudo apt-get install ros-groovy-moveit-ros-planning-interface`). Once installed, add
68+
the following code to your Python node:
69+
70+
from moveit_ros_planning_interface._moveit_roscpp_initializer import roscpp_init
71+
roscpp_init('node_name', [])
72+
73+
Now everything should work fine.
74+
5775
References
5876
----------
5977

6078
Some references that were helpful for me in one or the other way:
6179

80+
* This page, that I unfortunatly only found after I figured most of it out by myself, should
81+
explain everything...
82+
http://wiki.ros.org/ROS/Tutorials/Using%20a%20C%2B%2B%20class%20in%20Python
6283
* Boost::Python documentation: http://www.boost.org/doc/libs/1_57_0/libs/python/doc/index.html
6384
* Using Boost::Python with cmake: https://www.preney.ca/paul/archives/107
6485
* https://github.com/ethz-asl/Schweizer-Messer/wiki/Adding-boost::python-exports-to-your-ROS-package

scripts/use_cpplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
import boostpy_test.libmycpplib as cpp
3+
import boostpy_test.mycpplib as cpp
44

55
# this is the equivalent to `main()` in c++
66
if __name__ == '__main__':

src/mycpplib.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ void hello()
1010

1111

1212
// name has to match with the name in CMakeLists `add_library` + prefix 'lib'
13-
BOOST_PYTHON_MODULE(libmycpplib)
13+
BOOST_PYTHON_MODULE(mycpplib)
1414
{
1515
using namespace boost::python;
1616
def("hello", hello);

0 commit comments

Comments
 (0)