gcc 编译时使用-D参数可以传参给程序
- gcc -DDEBUG -D 后面直接跟宏命,相当于定义这个宏,默认这个宏的内容是1
- gcc -DNAME=Peter -D 后面跟 key=value 表示定义key这个宏,它的内容是value
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/un.h>
int main()
{
printf("%d\n", DEBUG); //DEBUG为编译传入的参数
return 0;
}
以下分别为DEBUG参数等于2和使用默认值时的输出结果