Python调用返回值为字符串的C函数(C库) 先写一个简单的C程序,定义函数hello。 #include <stdio.h> #include <stdlib.h> char* hello(){ return "hello"; } 编译成so文件 gcc -o hello.so -shared -fPIC hello.c 写python文件调用hello import ctypes from ctypes import * ll = ctypes.cdll.LoadLibrary lib = ll("./hello.so") s=lib.hello s.restype=c_char_p s=s() print s print '***finish***' 注意要加上s.restype=c_char_p Filed under: C/C++,Python,编程,跨语言编程 - @ 2021年9月2日 上午9:57