gcc的-D和-U参数:宏的设置与取消
来源:互联网 发布:编程培训机构logo 编辑:程序博客网 时间:2024/05/15 18:12
/********************************************************************************************************************************
原文地址:http://www.linuxdiyf.com/viewarticle.php?id=21325
转载说明:这个是-D的升级版!! 这个-U只对-D起作用,对-imacros不行。
********************************************************************************************************************************/
这两天做LFS注意到了gcc的-D参数:在gcc命令中定义宏,比如我有如下的代码:
CODE:
/* hello.c */
#include <stdio.h>
#ifdef YES
char* str = "Yes, this is a macro.";
#else
char* str = "No, there is no macro.";
#endif
int main()
{
printf("%s\n", str);
return 0;
}
#include <stdio.h>
#ifdef YES
char* str = "Yes, this is a macro.";
#else
char* str = "No, there is no macro.";
#endif
int main()
{
printf("%s\n", str);
return 0;
}
使用-D传入宏YES来进行编译:
CODE:
recordus@LFS test # gcc -DYES -o helloyes hello.c
recordus@LFS test # ./helloyes
Yes, this is a macro.
recordus@LFS test # ./helloyes
Yes, this is a macro.
而不传入宏则是这样的:
CODE:
recordus@LFS test # gcc -o hellono hello.c
recordus@LFS test # ./hellono
No, there is no macro.
recordus@LFS test # ./hellono
No, there is no macro.
gcc还有与-D对应的另一个参数-U用于取消宏,比如:
CODE:
root@LFS test # gcc -DYES -UYES -o helloyesno hello.c
root@LFS test # ./helloyesno
No, there is no macro.
root@LFS test # ./helloyesno
No, there is no macro.
这大概是这两个参数最简单的应用了:)
- gcc的-D和-U参数:宏的设置与取消
- gcc的-D和-U参数:宏的设置与取消
- gcc的-D和-U参数:宏的设置与取消
- gcc的-D和-U参数
- java的classpath设置与-D命令参数的用法
- makefile的和gcc参数
- g++和gcc的比较 与参数分析
- drupal面包屑导航的设置与取消
- apt代理的设置与取消
- 本地推送的设置与取消
- Git代理的设置与取消
- 自动播放 的设置和取消
- 数据库只读的设置和取消
- Linux 图形界面登录的取消和设置
- 用gcc 的-D 参数来调试代码
- 用gcc 的-D 参数来调试代码
- 用gcc 的-D 参数来调试代码
- GCC -L-l -D -I 参数的用法
- kmalloc、vmalloc、malloc的区别
- Android的Bitmap与Drawable
- 南京师范大学2011年GIS-数据结构考研试题
- 血管增强的各向异性扩散滤波(VED算法)
- Windows 7系统安装MySQL5.5.21图解
- gcc的-D和-U参数:宏的设置与取消
- 浅析MySQL数据库磁盘I/O调整优化
- 南京师范大学2010年GIS-数据结构考研试题
- [ZZ]计算机视觉、模式识别、机器学习常用牛人主页链接
- Gstreamer初见
- 南京师范大学2011年GIS考研试题
- OpenGL关照设置二
- MySQL数据库性能优化之缓存参数优化
- mysql运维