使用CFFI导入时,库中找不到变量

时间:2017-09-05 20:04:24

标签: python python-cffi cffi

我正在尝试加载以下.h文件:

3 typedef struct {
4     uint8_t clock_pin;
5 } pinout;
6 
7 pinout foo = {.clock_pin = 5};
8 pinout bar = {.clock_pin = 4};

使用以下python文件:

1 from pathlib import Path
2 import cffi
3 
4 FFI = cffi.FFI()
5 
6 with open(str(Path(__file__).parent.joinpath('lib', 'pins', 'pinout.h'))) as f:
7     FFI.embedding_api(''.join([line for line in f if not line.startswith('#')]))
8 
9 PINOUT = FFI.dlopen('c')

当我试图获取foo时,我收到以下错误:

>>> PINOUT.foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/anaconda3/envs/cmp/lib/python3.6/site-packages/cffi/api.py", line 802, in <lambda>
    lambda self: read_variable(BType, name),
KeyError: "variable 'foo' not found in library 'libc.so.6': /lib/x86_64-linux-gnu/libc.so.6: undefined symbol: foo"

值得注意的是,我为另一个我定义枚举的头文件设置了相同的设置,并且可以使用我在此处尝试使用的相同符号来解决枚举的各个元素。

0 个答案:

没有答案