通过使用 gcc 编译选项 快速定位头文件路径,解决编译中的问题

C / C++ 当项目过于庞大的时候经常会出现有些头文件有多份拷贝。

如下图所示:

有可能会出现 多份相同的头文件里面代码却不一致的情况

如果恰巧引用了这样的头文件,可能会导致编译错误,

比如:

A 目录下的   xx.h 有一个变量  h;

B 目录下的   xx.h  没有变量    h;

我们编译路径中可能引用的是 B 目录下面的 xx.h  就有可能 导致 访问不存在的变量 h 而导致编译问题。

那么怎么快速定位到我们引用的头文件的路径呢?

gcc  有相关编译选项 -MMD  或者 -MD

`-MD'
     `-MD' is equivalent to `-M -MF FILE', except that `-E' is not
     implied.  The driver determines FILE based on whether an `-o'
     option is given.  If it is, the driver uses its argument but with
     a suffix of `.d', otherwise it take the basename of the input file
     and applies a `.d' suffix.

     If `-MD' is used in conjunction with `-E', any `-o' switch is
     understood to specify the dependency output file (but *note -MF:
     dashMF.), but if used without `-E', each `-o' is understood to
     specify a target object file.

     Since `-E' is not implied, `-MD' can be used to generate a
     dependency output file as a side-effect of the compilation process.

`-MMD'
     Like `-MD' except mention only user header files, not system
     header files.

一般加在 我们 Makefile 文件的 gcc 的  FLAGS 里面,根据不同的变量自行修改便可.

在 执行 make 进行编译,会得到一个  xx.cpp  => xx.d 的文件。

用编辑器打开便可以看到完整的头文件路径:

从图中可以清晰的看到所使用的头文件的路径

是用的   application/share/webapp_frame/include/webapp_headinfo.h 

而不是   server/share/webapp_frame/include/webapp_headinfo.h 文件

这样可以便于快速定位和修复一些编译上面的问题。

转载于:https://my.oschina.net/tsh/blog/870209

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值