预编译阶段查看模块生成目标的层级依赖首先需要找到需要包含头文件的位置,然后进行引入。
示例:
1)用户头文件
/*@brief design and implements of demo-for-precompile.@author wen`xuanpei@email 15873152445@163.com(query for any question here)
*/
#pragma once
#ifndef __ARITHMETIC_H_
#define __ARITHMETIC_H_#define INT_A (10)
#define INT_B (20)#define max(a, b) ( (a) > (b) ? (a) : (b) )#endif
2)用户程序
/*@brief test demo-for-precompile-to-include? show you here@author wen`xuanpei@email 15873152445@163.com(query for any question here)
*/
#include "arithmetic.h"
#include <stdio.h>int main(){puts("hello world!\n");printf("max(%d,%d):%d\n", INT_A, INT_B, max(INT_A, INT_B));return 0;
}
3)预编译
gcc -o e3 test1.c -E -M
g++ -o e3 test1.c -E -M
4)查看模块生成目标的层级依赖
test1.o: test1.c /usr/include/stdc-predef.h arithmetic.h \/usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h \/usr/include/gnu/stubs-64.h \/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stddef.h \/usr/include/bits/types.h /usr/include/bits/typesizes.h \/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \/usr/lib/gcc/x86_64-redhat-linux/4.8.5/include/stdarg.h \/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h
尾声:
如果不知道如何寻找头文件,可以参考:gcc/g++:预编译阶段寻找头文件-CSDN博客