1、python调用c/c++ 函数

#include <stdio.h>
 
int func(int a,int b)
{
    printf("a=%d\n",a);
    printf("b=%d\n",b);
}
 
int main()
{
    int a=10;
    int b=20;
 
    func(a,b);
 
    return 0;
}

python代码

# python 调用 c/c++ 文件 执行
from ctypes import *
#dll = CDLL("export.dll")
a_cfile = windll.LoadLibrary("a.dll") # 调用C 和 C++ 文件
# gcc -shared -o a.dll .\a.c  编译为.dll 文件
a =10
b =20
a_cfile.func(a,b)
print("hello world !")