python学习笔记--使用ctypes调用C函数
来源:互联网 发布:退出淘宝客 之前的链接 编辑:程序博客网 时间:2024/05/24 08:33
将C文件编译成共享库
将下面代码保存为sam.c
//sam.c#include <stdio.h>int add(int a,int b){ return a+b;}
用gcc编译成.so文件
>gcc -fpic -c sam.c
>gcc --shared -fpic -o sam.so sam.o
之后可以调用C函数
>>> from ctypes import cdll>>> lib = cdll.LoadLibrary('F:\\sam.so')>>> lib.add(10,20)30
>>>import ctypes>>>from ctypes import cdll>>>lib = cdll.LoadLibrary('F:\\sam.so')>>>_add=lib.add #int add(int,int)</span>>>>_add.argtypes=(ctypes.c_int,ctypes.c_int) #如果add只有一个参数,应改为_add.argtype=......>>>_add(10,20)30
如果执行import sam出错请用sys.path.insert方法将sam所在路径导入。
0 0
- python学习笔记--使用ctypes调用C函数
- Python 使用ctypes调用 C 函数
- Python调用ctypes使用C函数printf
- Python 使用ctypes调用 C 函数
- 【转】Python调用ctypes使用C函数printf
- Python使用ctypes调用C函数传参处理
- Python 使用ctypes调用C/C++
- python使用ctypes调用C/C++
- ctypes: 使用python调用C编写的动态链接库
- Python 使用库ctypes调用C代码接口
- Python:使用ctypes库调用外部DLL(附带ctypes c 类型转换图)
- python ctypes - python调用C语言库
- Python 外部函数调用库ctypes简介
- Python:使用ctypes库调用外部DLL
- Python:使用ctypes库调用外部DLL
- Python:使用ctypes库调用外部DLL
- 使用ctypes调用kernel32.dll中的函数
- 使用ctypes调用C共享库中函数返回值为链表式结构时的方法
- node.js入门小实例
- 单例模式(转载)
- install mysql for mac
- 预处理中的“#”运算符和“##”运算符
- android多线程学习---Loader分析
- python学习笔记--使用ctypes调用C函数
- AndroidManifest合并原理
- WORD Application.Documents.Open函数返回null的一种解决方法
- AC自动机——多模式串的匹配
- android中跳转相册,相机获取图片后截取图片并保存SDCARD
- (转)ARM协处理器CP15寄存器详解
- android studio中gradle版本问题的解决方案
- Matlab的bsxfun函数
- EndNote X7 添加到word/office标题栏的设置