gcc编译选项-include和-Wall

一 选项-include

1 点睛

gcc命令行中也能包含头文件。很多开源软件都是这样,有的时候开源软件源码中找不到“#include <xxx.h>”这样的代码,而xxx.h的内容又确实被引用了。这就是-include搞的鬼。在gcc编译时通过-include来保护xxx.h。

2 使用方式

gcc [srcfile] -include [headfile]

3 实战

1 目录结构

[root@localhost 2.14]# vi inc/test.h
[root@localhost 2.14]# tree
.
├── inc
│   └── test.h
└── test
    └── test.cpp

2 test.h内容

#define ZWW 9

3 test.cpp内容

#include <stdio.h>
// 注意:本文件没有包含test.h
int main()
{
    bool b = false;
    printf("hello, boy:%d\n",ZWW);
    return 0;
}

4 运行结果

[root@localhost test]# gcc test.cpp -include /root/C++/ch02/2.14/inc/test.h -o test
[root@localhost test]# ./test
hello, boy:9

二 选项-Wall</

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值