Skip to content

Instantly share code, notes, and snippets.

@jarvisschultz
Last active August 11, 2019 17:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarvisschultz/bcb1ba233317f42e83ae to your computer and use it in GitHub Desktop.
Save jarvisschultz/bcb1ba233317f42e83ae to your computer and use it in GitHub Desktop.
Embedding Python in C++ Test
cmake_minimum_required(VERSION 2.8.3)
project(pycpp_test)
find_package(catkin REQUIRED COMPONENTS
roscpp
)
find_package(PythonLibs 3.4 EXACT)
catkin_package()
add_executable(fault_detector fault_detector.cpp)
target_link_libraries(fault_detector ${catkin_LIBRARIES} ${PYTHON_LIBRARIES})
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <python3.4/Python.h>
int main(int argc, char *argv[])
{
ros::init(argc, argv, "fault_detector");
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print('Today is', ctime(time()))\n");
Py_Finalize();
return 0;
}
<?xml version="1.0"?>
<package>
<name>pycpp_test</name>
<version>0.0.0</version>
<description>The pycpp_test package</description>
<maintainer email="todo@todo.todo">jarvis</maintainer>
<license>TODO</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<run_depend>roscpp</run_depend>
</package>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment