python 调用 C语言函数
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python 调用 C语言函数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.                        
                                python可以直接調(diào)用C語(yǔ)言的函數(shù),本文記錄用ctypes調(diào)用c語(yǔ)言的方法。
test.c
#include <stdio.h>int test(char *temp) {printf("temp:%s\n", temp);return 0; }編譯成動(dòng)態(tài)庫(kù)
gcc test.c -fPIC -shared -o libtest.so
test.py
#!/usr/bin/env python import osfrom ctypes import * # 加載動(dòng)態(tài)庫(kù) t = cdll.LoadLibrary(os.getcwd() + '/libtest.so') # 調(diào)用其中的函數(shù) t.test('hello'.encode())運(yùn)行結(jié)果
qt@tony:~$ ./test.py temp:helloTony Liu
2017-6-2, Shenzhen
總結(jié)
以上是生活随笔為你收集整理的python 调用 C语言函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Google 在开源上的贡献
 - 下一篇: jq 地区(省市县区)联动菜单