pythton 调用 so 共享库不能转换参数类型
windwiny
windwiny.ubt at gmail.com
Mon Jun 2 22:51:43 EDT 2008
我初学python 的 ctypes, 现在的环境是 ubuntu 8.04, Python 2.5.2 (r252:60911,
May 7 2008, 15:19:09) , gcc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
我创建了一个 so 共享库
---------------------
#include <math.h>
double myfd(double x) { return x * 2;}
float myff(float x) { return x * 3;}
int myfi(int x) { return x * 4 ;}
---------------------
用 gcc -shared a.c -o liba.so 来生成了一个 liba.so ,
用其它 c 程序链接这个库,里面的函数是能正确运行的
我写了一个python 程序
---------------------
# coding:utf-8
import ctypes as dll
p = dll.cdll.LoadLibrary("./liba.so")
print p.myfi(8) # 得32,正确
try:
print p.myfd(0.3) # 出错
except:
print "except myfd()"
try:
print p.myff(0.4) # 出错
except:
print "except myff()"
---------------------
出错提示为 ctypes.ArgumentError: argument 1: <type 'exceptions.TypeError'>:
Don't know how to convert parameter 1
这是什么原因?
More information about the Python-list
mailing list