本文主要是介绍python ctypes - python调用C语言库,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自:http://blog.sina.com.cn/s/blog_967817f20101a958.html
from ctypes import *
so = CDLL('./foo.so')
myprint = so.myprint
myprint.argtypes = [POINTER(c_char)]
myprint.restype = c_char_p
res = myprint("hello")
print res
add = so.add
add.argtypes = [c_float, c_float]
add.restype = c_float
print add(1.2, 3.3)
from ctypes.util import find_library
libc = find_library('c')
libc_so = CDLL(libc)
printf = libc_so.printf
printf("%d\n",2*2)
这篇关于python ctypes - python调用C语言库的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!