- 本文主要实现在linux环境下编写cpp文件调用python文件中的模块
代码块
- c++/hello.cpp
#include "Python.h"
#include <iostream>
using namespace std;
int main(){
// 初始化
Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject * pName = NULL; //声明变量
PyObject * pModule = NULL;
PyObject * pFunc = NULL;
PyObject * pDict = NULL;
pName = PyString_FromString("hello");
pModule = PyImport_Imp