Results 1 to 2 of 2

Thread: [SOLVED] Outputting to terminal for a debug compile only?

  1. #1
    Join Date
    Feb 2007
    Beans
    281

    Question [SOLVED] Outputting to terminal for a debug compile only?

    C++: I'm working on a program and I decided the other day to include code to output information to terminal with which I could debug it. Specifically I want to know if there is a way to make the compiler ignore my code when I am not compiling a debug version, or short of that, a way to get my program to output essentially all of it's information to terminal in a way that is humanly legible, without adding a lot of new code.

  2. #2
    Join Date
    Jul 2008
    Location
    Dublin, Ireland
    Beans
    633
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Outputting to terminal for a debug compile only?

    Quote Originally Posted by Zeotronic View Post
    C++: I'm working on a program and I decided the other day to include code to output information to terminal with which I could debug it. Specifically I want to know if there is a way to make the compiler ignore my code when I am not compiling a debug version, or short of that, a way to get my program to output essentially all of it's information to terminal in a way that is humanly legible, without adding a lot of new code.
    Classic solution is through the use of macros, something in the line of:

    Code:
    #ifdef _DEBUG
    // Either std::cout or printf would be fine.
    #define DEBUG(x) std::cout << x << std::endl
    #else
    #define DEBUG(x)
    #endif
    But I would go for a logging library for any but the simplest problems. Logging libraries are quite easy to use and they allow you to log/ignore logs at runtime with just a small runtime penalty. I use ACE for that (company decision), but I used before log4cpp and it was really flexible and powerful. You can look into Boost logging library (I don't know if it was yet approved into Boost, but it is quite good)

Bookmarks

Posting Permissions

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