gcc编译的时候提供了预定义功能,参数是-D,  通过man gcc可以了解更多:
-D name
           Predefine name as a macro, with definition 1.

       -D name=definition

Predefine name as a macro, with definition definition. 

The contents of definition are tokenized and processed as if they appeared during translation phase three in a #define directive. 

In particular, the definition will be truncated by embedded new-line characters.

 


可以通过以下例子解释一下:
int main()
{
    #ifdef HELLO
    printf("HELLO defined\n");
    #else
    printf("HELLO not define\n");
    #endif

    return 0;
}
在该程序中,判断是否已经定义了宏DEBUG,从而输出相应的语句。
如果编译该程序时采用了gcc -DHELLO, 则输出:HELLO defined

(也可以在makefile中直接给变量赋值    DEFS =   -DHAVE__PROGNAME=1)

相关文章:

  • 2022-01-21
  • 2021-12-14
  • 2022-03-05
  • 2022-02-10
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2021-12-28
  • 2021-10-05
  • 2021-12-22
  • 2022-12-23
相关资源
相似解决方案