g++ -D compiler options - Linux

This is a discussion on g++ -D compiler options - Linux ; I have some C++ package files, which are currently compiled using a command line syntax as follows: g++ -Ddebian -D_GNU_SOURCE -g -O2 -fno-rtti -fno-exceptions -Wall -Wno-trigraphs -DUSE_TERMIO -DKLUDGELINEMODE foobar.cc -c What are the effects of the -D options? -Ddebian -D_GNU_SOURCE ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: g++ -D compiler options

  1. g++ -D compiler options

    I have some C++ package files, which are currently compiled using a command
    line syntax as follows:

    g++ -Ddebian -D_GNU_SOURCE -g -O2 -fno-rtti -fno-exceptions -Wall
    -Wno-trigraphs -DUSE_TERMIO -DKLUDGELINEMODE foobar.cc -c

    What are the effects of the -D options?

    -Ddebian
    -D_GNU_SOURCE
    -DUSE_TERMIO
    -DKLUDGELINEMODE

    The gcc manual states:

    -D name
    Predefine name as a macro, with definition 1.

    I tried to locate references using:

    grep debian *.cc *.h
    grep _GNU_SOURCE *.cc *.h

    These return nothing.

    I did however find #ifdef and #ifndef references for USE_TERMIO and
    KLUDGELINEMODE.

    Presumably, the -DUSE_TERMIO -DKLUDGELINEMODE options cause inclusion of the
    enclosed definitions (or exclusion in the case of #ifndef).

    What about the -Ddebian -D_GNU_SOURCE options? Can I just drop these?

    FYI, The packages sources are the separated client component of
    the netkit-telnet package and am trying to achieve a build using
    autotools.

    Regards,

    Mark.

    --
    Mark Hobley,
    393 Quinton Road West,
    Quinton, BIRMINGHAM.
    B32 1QE.

  2. Re: g++ -D compiler options

    Mark Hobley wrote:

    > I have some C++ package files, which are currently compiled using a
    > command line syntax as follows:
    >
    > g++ -Ddebian -D_GNU_SOURCE -g -O2 -fno-rtti -fno-exceptions -Wall
    > -Wno-trigraphs -DUSE_TERMIO -DKLUDGELINEMODE foobar.cc -c
    >
    > What are the effects of the -D options?
    >
    > -Ddebian


    I've never seen that one before.

    > -D_GNU_SOURCE


    That one is quite common in system header files.

    > Presumably, the -DUSE_TERMIO -DKLUDGELINEMODE options cause inclusion of
    > the enclosed definitions (or exclusion in the case of #ifndef).


    Yes.

    > What about the -Ddebian -D_GNU_SOURCE options? Can I just drop these?


    _GNU_SOURCE is probably used to include or exclude stuff in the
    system header files.

    The main factor in deciding if they are needed or not is if the
    code compiles correctly without them. If it compiles correctly
    without these defines then they aren't beeded.

    Erik
    --
    -----------------------------------------------------------------
    Erik de Castro Lopo
    -----------------------------------------------------------------
    "When your hammer is C++, everything begins to look like a thumb."
    -- Steve Haflich, in comp.lang.c++

  3. Re: g++ -D compiler options

    markhobley@hotpop.donottypethisbit.com (Mark Hobley) writes:

    > What are the effects of the -D options?
    >
    > -Ddebian
    > -D_GNU_SOURCE
    > -DUSE_TERMIO
    > -DKLUDGELINEMODE


    Run gcc -c, with and without -E, one file at the time, one -D at the time,
    and save the output of each run into a different file. Compare the files
    and you'll see that the effects are.

    -- H


  4. Re: g++ -D compiler options

    Mark Hobley wrote:
    >
    > What are the effects of the -D options?
    >
    > -Ddebian
    > -D_GNU_SOURCE
    > -DUSE_TERMIO
    > -DKLUDGELINEMODE
    >


    These effectivly insert #defines in the preprocessor stage. Hence if you
    compile with -Ddebian, and in your code you have

    #ifdef debian
    some code
    #else
    some other code
    #endif

    The -Ddebian is equivalent to inserting a line which says

    #define debian

    at the top of the C file you're currently compiling.

    Instead of debian you could substute BobTheBuilder and it would still do the
    same. It's just a symbol. The _GNU_SOURCE has a particular meaning in the
    GNU C library (and a few other places) - it makes the header recognise
    certain GNU extensions which are not quite POSIX-compliant (e.g. if you want
    to have the strsignal() function available in string.h you have to define
    _GNU_SOURCE before including it - you can do that using this flag).

    Cheers,

    - Daniel
    --
    ************************************************** ***********************
    * Daniel Franklin - Lecturer in Computer Engineering
    * University of Wollongong, NSW, Australia * d.franklin at ieee.org
    ************************************************** ***********************

  5. Re: g++ -D compiler options

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.6 (GNU/Linux)

    iD8DBQFH7Cy8VcFcaSW/uEgRAlcKAKDrlVev1LjPGYSHgVwg+sFS5/VQbQCfR7vf
    CKZLfIGKl2n8raIapojm5W4=
    =kiaj
    -----END PGP SIGNATURE-----

+ Reply to Thread