向 cffi 编译过程添加标志

tal*_*tal 4 python pypy python-cffi

我使用 cffi 模块来包装简单的 C 代码。问题是,我需要添加一个标志来使其编译(std=c99)。目前我有类似的东西:

from cffi import FFI
ffibuilder = FFI()
with open("test.c", 'r') as f:
    ffibuilder.set_source("mymodule", f.read()) 
with open("test.h", 'r') as f:
    ffibuilder.cdef(f.read())
if __name__ == "__main__":
    ffibuilder.compile(verbose=True)
Run Code Online (Sandbox Code Playgroud)

问题是,cffi 自己调用 gcc,我想将 std=c99 添加到它调用 gcc 的标志中。我缺少任何参数吗?

(注意:我可以更改 gcc 命令本身或运行 cffi 自己使用的 gcc 命令,我想知道我是否缺少一些正确的方法来执行此操作)

tal*_*tal 8

我最终找到了答案:

set_source接受extra_compile_args参数: 所以你可以调用:

ffibuilder.set_source(..., extra_compile_args=["-std=c99"])