How to pass macro definition from “makefile” command line arguments to C source code?

来源:互联网 发布:淘宝神店 知乎 编辑:程序博客网 时间:2024/05/18 01:32
1
2
3
4
5
6
7
8
#FILENAME:Makefile

export SAI=y
 
ifeq ($(SAI),y)
CFLAGS += -DSAI
endif
 
all:
    @gcc $(CFLAGS) macro_test.c -o macro_test

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*FILENAME:macro_test.c*/
#include <stdio.h>
#include <stdlib.h>
 
int
main(int argc, char* argv[])
{
#ifdef SAI
    printf("I am in SAI env\n");
#endif
 
    printf("hi everyone\n");
 
    return 0;
}

  

在Makefile中  把

export SAI=y or SAI=n

就可以決定有沒有定義SAI在C code中


0 0
原创粉丝点击