1

I have a python package that uses a C extension. The C code has preprocessor directives, like

#ifdef FLAG
    printf("with FLAG\n");
#else
    printf("without FLAG\n");
#endif

In setup.py this is then defined as an extension like this

cmodule = Extension('mytest',
                    sources=['src/code.c'],
                    include_dirs=['src'],
                    extra_compile_args=['-fstrict-aliasing', '-O3', '-std=c99', '-Wno-unknown-pragmas', '-D_GNU_SOURCE', '-fPIC']
                    extra_link_args=[],
                    )

How can I make the setup compile the extension with FLAG being set? I tried os.environ['FLAG'] = '1', but this doesn't seem to have an effect.

John Smith
  • 1,059
  • 1
  • 13
  • 35

0 Answers0