gcc compile and pass parameters to the program

Use the -D parameter when gcc is compiled to pass parameters to the program

  1. gcc -DDEBUG -D is directly followed by the macro command, which is equivalent to defining this macro. The default content of this macro is 1
  2. gcc -DNAME=Peter -D followed by key=value means to define the macro of key, and its content is 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;
}

The following are the output results when the DEBUG parameter is equal to 2 and the default value is used.
Insert picture description here

Guess you like

Origin blog.csdn.net/chengcheng1024/article/details/112321852