温馨提示×

python如何调用c函数

九三
189
2021-02-09 15:01:54
栏目: 编程语言

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

0