I am trying to build a shared library with CFFI for one of the Linux core utilities that I can call from Python. I have done this before for other C and C++ programs but this is my first attempt for one of the core utilities.
I finished modifying the utility's C code to provide a callable routine and I successfully tested it as a command-line program. The problem occurs when I attempt to compile it using CFFI.
When CFFI builds the C code to compile, it inserts a lengthy prefix of several hundred lines including an include of <Python.h> before it embeds the code of the core utility. This is normal but the core utilities include a header <config.h> that must precede other headers. The specific error I get is "Please include config.h first." generated by the header <unistd.h> which was included from the Python.h header.
Does CFFI provide a way to modify the prefix that it generates so that I can stick <config.h> in it before the Python.h include? I suppose I could discover a way to modify one of more headers to get around this problem but I'd like to avoid modifications like that. What is the best way to get around this problem?
If you're using GCC or Clang, the -include filename
option might help.
It includes the named file before anything else.
See GCC Preprocessor Options.