python c++混编
有人懂python 和c++混编吗,想请教一些问题
#include <python.h>
using namespace std;
int main(){
……
}
程序代码:
//c++
//Python调用c++(类)动态链接库
#include <iostream>
using namespace std;
class TestLib
{<!-- -->
public:
void display();
void display(int a);
};
void TestLib::display() {<!-- -->
cout<<"First display"<<endl;
}
void TestLib::display(int a) {<!-- -->
cout<<"Second display:"<<a<<endl;
}
extern "C" {<!-- -->
TestLib obj;
void display() {<!-- -->
obj.display();
}
void display_int(int a) {<!-- -->
obj.display(a);
}
}
程序代码:
import ctypes
dll = ctypes.cdll.LoadLibrary
lib = dll('./libpycallcpp.so') #刚刚生成的库文件的路径
lib.display()
lib.display_int(0)
