【发布时间】:2012-02-13 12:51:51
【问题描述】:
我写了一个python代码来将ctypes结构传递给c库函数
python 代码:
from ctypes import *
class Info(Structure):
_field_ = [("input",c_int),
("out",c_int)]
info = Info()
info.input = c_int(32)
info.out = c_int(121)
lib = CDLL("./sharedLib.so").getVal
a = lib(byref(info))
c 代码:
#include <stdio.h>
struct info{
int input;
int out;
};
void getVal(struct info *a){
printf("in = %i \n", a->input);
printf("out = %i \n", a->out);
}
使用命令编译它:
gcc -shared -fPIC -o sharedLib.so sharedLib.c
输出:
in = 0
out = 0
我的问题是,为什么输出与我在 python 代码中设置的值不同。有什么解决办法吗? 我在 32 位环境中
【问题讨论】: