conditional compilation

Discussion in 'C Programming' started by onkar.n.mahajan@gmail.com, Feb 4, 2009.

  1. Guest

    Hi All ,
    I want to compile some part of the file depending on some
    parameter set in the Makefile (using cc compiler ).

    for instance

    #ifdef CONDITION
    //include this part of the code in compilation
    #endif


    I need to only set/unset the option in Makefile. Is it possible to do
    this ?

    One example will be of great help.

    Thanks
    , Feb 4, 2009
    #1
    1. Advertising

  2. In article <>,
    <> wrote:
    > I want to compile some part of the file depending on some
    >parameter set in the Makefile (using cc compiler ).
    >for instance
    >#ifdef CONDITION
    > //include this part of the code in compilation
    >#endif
    >I need to only set/unset the option in Makefile. Is it possible to do
    >this ?


    In the Makefile set:

    CFLAGS = -DCONDITION -whatever-other-flags

    --
    Rouben Rostamian
    Rouben Rostamian, Feb 4, 2009
    #2
    1. Advertising

  3. In article <>,
    <> wrote:

    > I want to compile some part of the file depending on some
    >parameter set in the Makefile (using cc compiler ).
    >
    >for instance
    >
    >#ifdef CONDITION
    > //include this part of the code in compilation
    >#endif
    >
    >
    >I need to only set/unset the option in Makefile. Is it possible to do
    >this ?


    Most compilers accept a flag -Dname=value (or just -Dname if you don't
    care what value it is). Something like

    cc -DCONDITION -c myfile.c

    You may wish to put all your compiler flags in a Make variable, instead
    of repeating them on each cc line, e.g.

    CFLAGS= -O -g -DCONDITION
    ...
    cc $(CFLAGS) -c myfile.c

    (Actually CFLAGS is a special variable name; if you don't specify a
    rule for compiling C programs it will use $(CFLAGS) anyway.)

    Different versions of the Make program vary somewhat; if you want
    to do anything fancy you should probably find a group devoted to
    the particular variety you're using.

    -- Richard
    --
    Please remember to mention me / in tapes you leave behind.
    Richard Tobin, Feb 4, 2009
    #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. Chris P
    Replies:
    0
    Views:
    424
    Chris P
    Oct 28, 2003
  2. avishay

    Conditional compilation in VHDL

    avishay, Aug 1, 2005, in forum: VHDL
    Replies:
    4
    Views:
    2,976
    Andy Peters
    Aug 1, 2005
  3. Praveen
    Replies:
    0
    Views:
    341
    Praveen
    Apr 12, 2005
  4. Praveen Ramesh
    Replies:
    2
    Views:
    2,141
    Steven Cheng[MSFT]
    Apr 13, 2005
  5. Alec S.
    Replies:
    10
    Views:
    10,057
    Alec S.
    Apr 16, 2005
Loading...

Share This Page