extern "C" int add(int a, int b) // 注意:extern "C"必不可少
{
return a+b;
}
执行命令,生成so
python调包 测试文件test.pygcc -o liba.so -shared -fPIC a.cpp
import ctypes
ll = ctypes.cdll.LoadLibrary("liba.so")
print(ll.add(1, 3)) # 4
执行
python test.py
python3 test.py



