混编的含义有两种,
一种是在python里面写C
一种是C里面写python
本文主要是进行简化,方便使用。
#####################################################################################################
第一种、Python调用C动态链接库(利用ctypes)
pycall.c
/***gcc -o libpycall.so -shared -fPIC pycall.c*/
#include
#include
int foo(int a, int b)
{
printf("you input %d and %d\n", a, b);
return a+b;
}
pycall.py
import ctypes
ll = ctypes.cdll.LoadLibrary
lib = ll("./libpycall.so")
lib.foo(1, 3)
print '***finish***'
运行方法:
gcc -o libpycall.so -shared -fPIC pycall.c
python pycall.py
第2种、Python调用C++(类)动态链接库(利用ctypes)
pycallclass.cpp
#include
using namespace std;
class TestLib
{