Linux 拨号vps windows公众号手机端

python如何调用c函数

lewis 6年前 (2019-04-08) 阅读数 13 #程序编程
文章标签 c语言python

在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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门