假设在/root/Desktop/c 的目录下有如下两个文件:
/* hello.c */
#include<my.h>
int main()
{
printf("Hello! This is our embedded world!/n");
return 0;
}
/* my.h */
#include<stdio.h>
-I dir选项的功能是在头文件的搜索路径列表中添加 dir 目录
则可用-I 选项来包括my.h这个头文件(my.h用vi打开),如果没有包含该文件则会出错,如下:
[root@localhost ~]# cd Desktop/c
[root@localhost c]# gcc -E hello.c -o hello.i
hello.c:1:15: 错误:my.h:没有那个文件或目录
[root@localhost c]# gcc -E hello.c -I /root/Desktop/c -o hello.i
[root@localhost c]#
此外,若将hello.c文件中的 #include<my.h>改为 #include"my.h", 则不需要添加 -I 选项也可以执行