两种编译器调用命令
gcc -shared -o Test.dll Test.c
cl /LD test.c #直接编译成DLL文件
第一步 编写C语言文件 test.c 每个函数之前要有__declspec(dllexport) 声明,不然python无法调用
#include<stdio.h>
__declspec(dllexport) int sum(int a, int b)
{
return a + b;
}
__declspec(dllexport) int sub(int a,int b){
return a-b;
}
__declspec(dllexport) void say(void){
printf("hello world");
}
第二步 编译该文件为DLL 文件 使用命令 cl /LD test.c
生成test.dll文件
第三步 python调用 展示 main.py
from ctypes import *
from platform import *
print(system())
cdll_names = {
'Darwin' : 'libc.dylib',
'Linux' : 'libc.so.6',
'Windows': 'msvcrt.dll'
}
#加载库并调用库中函数 编写针对多个平台的调用 那么三个库都必须相同的函数 相同的功能 这
#里展示的是一个例子