Hello world!
This tutorial lets you export exactly 1 function from C++ to Python!
std::string hello()
{
PY_DECLARE_MODULE( embedding )
PY_MODULE_FUNCTION( embedding, hello )
PY_EXTENSION_MODULE( embedding )
The code hopefully speaks for itself but here we go nonetheless:{
return std::string("Hello world!");
}PY_DECLARE_MODULE( embedding )
PY_MODULE_FUNCTION( embedding, hello )
PY_EXTENSION_MODULE( embedding )
- PY_DECLARE_MODULE( embedding ) declares a Python extension module and gives it the name embedding.
- PY_MODULE_FUNCTION( embedding, hello ) adds the function hello to the module embedding. By default the name of the C++ is taken as name for the corresponding Python function name.
- PY_EXTENSION_MODULE( embedding ) generates the necessary function for Python to recognize the generated dll as an extension module.