I am trying to load the following .h file:
3 typedef struct {
4 uint8_t clock_pin;
5 } pinout;
6
7 pinout foo = {.clock_pin = 5};
8 pinout bar = {.clock_pin = 4};
Using the following python file:
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')
When I try to get foo I get the following error:
>>> 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"
It's worth noting that I have the exact same set up for another header file where I define an enum, and can address the individual elements of the enum using the same notation I tried using here.