Python 调用 C 语言 so

$ gcc -shared -Wl,-soname,testlib -o testlib.so -fPIC testlib.c
如果在Mac OS X ,则
$ gcc -shared -Wl,-install_name,testlib.so -o testlib.so -fPIC testlib.c

import ctypes


s0 = 'hello,www.cricode.com'

s1 = ctypes.create_string_buffer(s0)

testlib1 = ctypes.CDLL('./testlib1.so')

testlib1.reverse(s0)

print 's0 is: ',s0

print 's1 is: ',s1.value

引用:http://www.cricode.com/359.html 

原文地址:https://www.cnblogs.com/li-baibo/p/4192084.html