python如何调用c函数

1032
2021/2/9 15:01:54
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

python如何调用c函数

在python中使用ctypes模块调用c函数,具体方法如下:

from ctypes import * #导入ctypes模块

handle = cdll.LoadLibrary('libtest.so')

func = handle.printStr

func.argtypes = (c_char_p,c_char_p)

func.restype = c_char_p

tmp = handle.printStr("hello".encode("utf-8"),"world".encode("utf-8"))

print(tmp.decode("utf-8"))

输出结果为:

helloworld

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python中怎么用opencv读取图像数据