#include <Akita/Akita.h> #include <Python.h> int main() { Py_Initialize(); if (!Py_IsInitialized()) return FALSE; PyRun_SimpleString("import sys"); PyRun_SimpleString("sys.path.append('./')"); //import Module PyObject* pModule = PyImport_ImportModule("hello"); if (!pModule) { cout<<"Can't import Module!/n"<<endl; return -1; } PyObject* pDict = PyModule_GetDict(pModule); if (!pDict) { return -1; } //fetch Function PyObject* pFunHi = PyDict_GetItemString(pDict, "display"); PyObject_CallFunction(pFunHi, "s", "Crazybaby"); Py_DECREF(pFunHi); //Release Py_DECREF(pModule); Py_Finalize(); return 0; }
Python与C/C++ 模块相互调用
内容版权声明:除非注明,否则皆为本站原创文章。