在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