Define macro when invoking setup.py

Discussion in 'Python' started by Jason, Nov 9, 2010.

  1. Jason

    Jason Guest

    I'd like to be able switch between building my C extension with a
    certain preprocessor macro defined or not defined. I'm using the
    rudimentary distutils setup.py example given here:

    http://docs.python.org/extending/building.html

    Is there a command line option that distutils.core.setup() will
    interpret for me, like the "-D" option for gcc? Or do I need to do
    something more complicated? (I had a brief look at the
    distutils.command.build_* docs... but they're pretty sparse.)
    Jason, Nov 9, 2010
    #1
    1. Advertising

  2. Jason

    Jason Guest

    On Nov 9, 10:48 am, Christian Heimes <> wrote:
    > You were looking at the wrong manual. Readhttp://docs.python.org/distutils/setupscript.html#preprocessor-options
    >
    > Extension(...,
    >           define_macros=[('NDEBUG', '1'),
    >                          ('HAVE_STRFTIME', None)],
    >           undef_macros=['HAVE_FOO', 'HAVE_BAR'])
    >
    > Note that define_macros requires a list of tuples each having two members..


    But can they be selected or set from the command line, so I can do,
    say, "setup.py build -DDEBUG=1"?

    — Jason
    Jason, Nov 9, 2010
    #2
    1. Advertising

  3. Jason

    Jason Guest

    On Nov 9, 10:56 am, Jason <> wrote:
    > But can they be selected or set from the command line, so I can do,
    > say, "setup.py build -DDEBUG=1"?


    Just answered my own question: there's an option for "build_ext" (NOT
    "build") that allows this.

    Thanks,
    Jason
    Jason, Nov 9, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dead RAM
    Replies:
    20
    Views:
    1,111
    John Harrison
    Jul 14, 2004
  2. Wade
    Replies:
    1
    Views:
    370
  3. D Senthil Kumar

    macro name from macro?

    D Senthil Kumar, Sep 20, 2003, in forum: C Programming
    Replies:
    1
    Views:
    578
    Jack Klein
    Sep 21, 2003
  4. sounak

    to get macro name from macro value

    sounak, Nov 22, 2005, in forum: C Programming
    Replies:
    17
    Views:
    501
    Mark McIntyre
    Nov 22, 2005
  5. Francesc

    Invoking setup.py in sub-packages

    Francesc, May 13, 2010, in forum: Python
    Replies:
    0
    Views:
    385
    Francesc
    May 13, 2010
Loading...

Share This Page