首页 > 技术文章 > Python 调用 C 语言 so

li-baibo 2014-12-29 17:24 原文

$ 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 

 

推荐阅读