【Linux】借助gcc源码修改,搜索头文件当前进展
测试代码:
log.h
#ifndef LOG_H
#define LOG_Hint add(int a, int b); #endif
log.c
#include <stdio.h>
#include <stdlib.h>#include "log.h"int add(int a, int b)
{int c = a + b;printf("c=%d", c);return c;
}
test.c
#include "log.h"int main()
{add(1, 2);return 0;
}
auto_test.sh
echo "" > /log.txt
gcc test.c log.c -o test
./test
grep -Hrn "log.h" /log.txt
grep -Hrn "stdio.h" /log.txt
grep -Hrn "test.c" /log.txt
运行的结果:
这里的日志是编译时将头文件所在的目录添加到编译的头文件搜索目录列表
这里的大概的意思是在编译test.c, log.c的时候对外依赖的头文件
gcc的代码量比较大,看了很小些gcc源代码,慢慢摸索才找到这里。
当前碰到一个比较大的问题,就是在编译的时候会生成一些中间文件,在/tmp目录,编译时需要不停的按enter键,才能继续往下编译。。。。。
这只是大概 找到的位置,也不确定是否正确。
从另一方面来说,在内核编译中后期会进行链接,也会报一些头文件不能识别,这块估计得下一步继续摸索。。。
感谢阅读。