Find the answer to your Linux question:
Results 1 to 2 of 2
Hi Gurus, I have a quick question. I am supposed to implement a Debug trace when my project is compiled with gcc -DDEBUG option. I declared a macro as such: ...
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    34

    gcc -DDEBUG option

    Hi Gurus,

    I have a quick question. I am supposed to implement a Debug trace when my project is compiled with gcc -DDEBUG option.

    I declared a macro as such:

    #ifdef _DEBUG
    #define DEBUG_TRACE(x) printf("%s\n", (x))
    #else
    #define DEBUG_TRACE(x)
    #endif

    Then in my code, I am using the DEBUG_TRACE macro. However, I am not outputiing my debug statements wven after compiling with the gcc -DDEBUG option. Can someone please point me what am I doing wrong?
    PS: I tried different options like just DEBUG etc. with no avail.

    -Thanks in advance
    rabantu

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    You have two choices.

    First, you can compile with this:

    Code:
    gcc -D_DEBUG
    But a better choice is to do this:

    Code:
    #ifdef DEBUG     /* not _DEBUG */
    The reason is that in C you should avoid using identifiers that begin with an underscore, to avoid collision with identifiers used by those who implement the compiler.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...