Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4733359
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: LINUX

2010-04-24 16:47:59

写程序的时候经常都需要有debug信息,可是到最后release的时候是不需要调试信息的,一般我会定义一个DEBUG宏
 
 

#ifdef DEBUG
#define XX_DEBUG(format,args...) \
fprintf(stderr, format, ##args)
#else
#define XX_DEBUG(format,args...)
#endif

 

那么这个DEBUG宏如何传进去呢? 又我需要这个DEBUG是某个整形值的时候呢? 字符串呢?
我需要gcc又需要Make的so

下面就是你想要的了

 

[kenthy@kenthy debug]$ cat debug.c
#include <stdio.h>

int main()
{
 #ifdef DEBUG
  printf("%s\n", "define debug");
 #else
  printf("%s\n", "not define debug");
 #endif

 #ifdef DEBUG_I
  printf("%s\n", "define debug_i");
  printf("value is:%d\n", DEBUG_I);
 #else
  printf("%s\n", "not define debug_i");
 #endif

 #ifdef DEBUG_S
  printf("%s\n", "define debug_s");
  printf("value is:%s\n", DEBUG_S);
 #else
  printf("%s\n", "not define debug_s");
 #endif
 
 return 0;
}
[kenthy@kenthy debug]$ gcc -Wall -DDBUG -DDEBUG_I=1 -DDEBUG_S=\"hello\" -o debug debug.c
[kenthy@kenthy debug]$ ./debug
not define debug
define debug_i
value is:1
define debug_s
value is:hello


[kenthy@kenthy debug]$ cat Makefile
TARGET=debug
OBJ=debug.o
CFLAG=-Wall -g -w
CC=gcc
#LIBS= -lpthread


## 输出样式 与编译无关
OFFSET=\x1b[41G
COLOR=\x1b[1;34m
RESET=\x1b[0m
CLEAR=\x1b[H\x1b[J


## 以后的不用修改
$(TARGET): $(OBJ)
    @echo -n "
Generating $@..."
    @if $(CC) $(CFLAG) -o $@ $^ $(LIBS); then echo -e "
$(OFFSET)$(COLOR)[ OK ]$(RESET)"; fi

%.o: %.c %.h
    @echo -n "
Compiling $<..."
    @if $(CC) $(CFLAG) -c -o $@ $<; then echo -e "
$(OFFSET)$(COLOR)[ OK ]$(RESET)"; else exit 1; fi

clean:
    @echo -n "
Cleanning up..."
    @rm -rf *.o *.bak *~ $(TARGET)
    @echo -e "
$(OFFSET)$(COLOR)[ OK ]$(RESET)"

clear:
    @echo -ne "
$(CLEAR)Cleanning up..."
    @rm -rf *.o *.bak *~ $(TARGET)
    @echo -e "
$(OFFSET)$(COLOR)[ OK ]$(RESET)"
[kenthy@kenthy debug]$ make CFLAGS="
-DDEBUG -DDEBUG_I=1 -DDEBUG_S=\\\"hello\\\""
gcc -DDEBUG -DDEBUG_I=1 -DDEBUG_S=\


DDEBUG_S=\\\"hello\\\" 这里的转义我也是体会了半天才体会出来的,赋值给CFLAGS的时候需转一次,shell又一次,需要需要三个\\\
阅读(1735) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-01 06:25:05

MBT is based on Africa's indigenous people to create innovative walking barefoot, and wear this shoe can stimulate the body to relax the muscles so that the muscles of heat to be released, consumed calories, thus to achieve weight loss results. MBT's pursuit of beauty in order to satisfy customers, design a variety of styles, such as Mbt Chapa shoe, MBT Lami Shoe