Last active
August 11, 2019 17:21
-
-
Save jarvisschultz/bcb1ba233317f42e83ae to your computer and use it in GitHub Desktop.
Embedding Python in C++ Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<package> | |
<name>pycpp_test</name> | |
<version>0.0.0</version> | |
<description>The pycpp_test package</description> | |
<maintainer email="[email protected]">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