查看C语言文件依赖关系(用-Wp,MD参数生成.d文件)
Posted 正在起飞的蜗牛
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查看C语言文件依赖关系(用-Wp,MD参数生成.d文件)相关的知识,希望对你有一定的参考价值。
1、-wp,-MD参数介绍
(1)在编译c源文件时使用该参数,会生成对应C源文件的.d格式的文件,.d格式的文件内容是C源文件的依赖关系;
(2)C源文件的依赖关系就是源文件调用了哪些头文件,可以方便我们确认工程中的同名头文件到底是引用的哪一份;
(3)在大型项目中(比如内核),有很多同名头文件,可能放在了不同平台、不同产品类型的目录下,本次编译到底引用的哪个路径下的头文件,并不能很直观
的看出来,这时候就可以通过-wp,-MD参数生成.d文件来看文件依赖关系;
2、Makefile中使用示例
dep_file = .$@.d
#Makefe的规则
%.o : %.c
$(CC) $(CFLAGS) -Wp,-MD,$(dep_file) -c -o $@ $<
(1)将.c文件编译成.o文件,并且将.c文件的依赖关系写到$(dep_file)文件中;
(2)上面Makefile的规则达到的效果:比如编译main.c文件,会生成main.o文件和.main.o文件;
注意:.main.o文件是隐藏文件,需要ls -a才能看到;
3、示例代码
3.1、main.c
#include <stdio.h>
#include <string.h>
//我自己写的头文件
#include "config.h"
#include "fb.h"
#include "bmp.h"
#include "decode_jpg.h"
#include "decode_png.h"
#include "imageManager.h"
#include "touchScreen.h"
int main(int argc, char *argv[])
······
3.2、.main.d文件
main.o: main.c \\
//编译链提供的头文件
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/stdc-predef.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/stdio.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/libc-header-start.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/features.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/sys/cdefs.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/wordsize.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/long-double.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/gnu/stubs.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/gnu/stubs-soft.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/lib/gcc/arm-linux-gnueabi/6.3.0/include/stddef.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/types.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/typesizes.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/libio.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/_G_config.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/wchar.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/lib/gcc/arm-linux-gnueabi/6.3.0/include/stdarg.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/stdio_lim.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/sys_errlist.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/stdio.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/string.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/xlocale.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/string.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/bits/string2.h \\
/opt/hisi-linux/x86-arm/arm-himix200v002-linux/target/usr/include/stdlib.h \\
//我自己写的头文件的路径
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/common/config.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/fb/fb.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/decode/bmp/bmp.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/decode/jpg/decode_jpg.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/decode/png/decode_png.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/imageManager/imageManager.h \\
/home/aston/study_myself/picturePlayer/myPlayer/build/../include/touchScreen/touchScreen.h
以上是关于查看C语言文件依赖关系(用-Wp,MD参数生成.d文件)的主要内容,如果未能解决你的问题,请参考以下文章