在一段C/C++代码中,如果我们想动态控制宏定义,可以通过GCC的编译选项进行控制。
如下代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
#ifdef DEBUG
printf("gcc 的-D 选项测试\n");
#endif
return 0;
}
我们可能在调试的时候需要动态打开DEBUG宏方便调试,如果直接编译,该宏定义是无法打开的:
~/cplusplus/gcc$ gcc debugtest.c -o debugtest.exe ~/cplusplus/gcc$ ./debugtest.exe
gcc/g++引入了-D的编译项,方便我们传入自己希望打开的宏:
~/cplusplus/gcc$ gcc debugtest.c -o debugtest.exe -D DEBUG ~/cplusplus/gcc$ ./debugtest.exe gcc 的-D 选项测试
文章的脚注信息由WordPress的wp-posturl插件自动生成

微信扫一扫,打赏作者吧~![[整理][转载]win下网卡抓包发包库Npcap使用](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2023/08/demo_1-1024x711.jpg&w=280&h=210&zc=1)
![[转载]基础数据char,int,double,string是线程安全的吗?](http://www.jyguagua.com/wp-content/themes/begin/img/random/13.jpg)
![[整理]用c++编写的RDTSC性能计时器](http://www.jyguagua.com/wp-content/themes/begin/timthumb.php?src=http://www.jyguagua.com/wp-content/uploads/2020/12/rdtsc-assembly-example.jpg&w=280&h=210&zc=1)
![[整理]strcmp汇编写法](http://www.jyguagua.com/wp-content/themes/begin/img/random/6.jpg)