Delete debug lines in release builds

I use the function LOG_DEBUGto print debug information on the screen. I used #define _DEBUGto disable the function LOG_DEBUGby defining _DEBUGFLAG at compile time (release time). but the linux stringsrelease build application commands still show the debug lines that exist in the compiled application. so what are the alternatives to eliminate the arguments LOG_DEBUG?

#ifdef _DEBUG
#define LOG_DEBUG(fmt, ...) printf("[D][%s:%d %s]", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__)
#else
#define LOG_DEBUG(fmt, ...)
#endif


LOG_DEBUG("this is a debug string");     // "this is a debug string" exists in app release build yet

I use the compiler: ARM/Thumb C/C++ Compiler, RVCT3.1 [Build 569]

Optimization: -O3

+6
source share
1 answer

You can try using stringification :

#include <stdio.h>

#define _DEBUG

#ifdef _DEBUG
#define LOG_DEBUG(str) do { printf("[D][%s:%d %s] ", \
                               __FILE__, \
                               __LINE__, \
                               __FUNCTION__); \
                            puts(#str); } while(0)
#else
#define LOG_DEBUG(str)
#endif

int main() {
  LOG_DEBUG(this is a debug string);
  return 0;
}

: clang, .

+3

All Articles