./
│ main.c
│
├─inc1
│ inc.h
│ inc1.c
│
└─inc2
inc.h
// ./main.c
extern int inc1(void);
int main(void)
{
printf("main VAL=%d\r\n",VAL);
printf("inc1 VAL=%d\r\n",inc1());
return 0;
}
// ./inc1/inc.h
// ./inc1/inc1.c
int inc1(void)
{
return VAL;
}
// ./inc2/inc.h
gcc .\main.c .\inc1\inc1.c -o main
.\main.c:2:10: fatal error: inc.h: No such file or directory
2 |
| ^~~~~~~
compilation terminated.
.\inc1\inc1.c:1:10: fatal error: inc.h: No such file or directory
1 |
| ^~~~~~~
compilation terminated.
gcc .\main.c .\inc1\inc1.c -Iinc1 -Iinc2 -o main
In file included from .\main.c:2:
inc1/inc.h:3:11: note: '#pragma message: inc1/inc.h'
3 |
| ^~~~~~~
In file included from .\inc1\inc1.c:1:
inc1/inc.h:3:11: note: '#pragma message: inc1/inc.h'
3 |
| ^~~~~~~
gcc .\main.c .\inc1\inc1.c -Iinc2 -o main
In file included from .\main.c:2:
inc2/inc.h:3:11: note: '#pragma message: inc2/inc.h'
3 |
| ^~~~~~~
In file included from .\inc1\inc1.c:1:
inc2/inc.h:3:11: note: '#pragma message: inc2/inc.h'
3 |
| ^~~~~~~
gcc .\main.c .\inc1\inc1.c -I -Iinc1 -Iinc2 -o main
得到的是
In file
included from .\main.c:2:
inc2/inc.h:3:11:
note: '#pragma message: inc2/inc.h'
3 |
| ^~~~~~~
In file
included from .\inc1\inc1.c:1:
inc2/inc.h:3:11:
note: '#pragma message: inc2/inc.h'
3 |
| ^~~~~~~
gcc .\main.c .\inc1\inc1.c -I./ -Iinc1 -Iinc2 -o main
In file included from .\main.c:2:
inc1/inc.h:3:11: note: '#pragma message: inc1/inc.h'
3 |
| ^~~~~~~
In file included from .\inc1\inc1.c:1:
inc1/inc.h:3:11: note: '#pragma message: inc1/inc.h'
3 |
| ^~~~~~~
gcc ./main.c ./inc1/inc1.c -o main
2:10: :
fatal error: inc.h: No such file or directory
2 | #include "inc.h"
^~~~~~~
compilation
terminated.
In file
included from ./inc1/inc1.c:1:
3:11: :
note: '#pragma message: ./inc1/inc.h'
3 | #pragma message(__FILE__)
^~~~~~~
gcc ./main.c ./inc1/inc1.c -Iinc2 -o main
In file
included from ./main.c:2:
inc2/inc.h:3:11:
note: '#pragma message: inc2/inc.h'
3 |
| ^~~~~~~
In file
included from ./inc1/inc1.c:1:
./inc1/inc.h:3:11:
note: '#pragma message: ./inc1/inc.h'
3 |
| ^~~~~~~
关注公众号“嵌入式软件实战派”,回复关键字include2即可获得本文测试源码+pdf版高清大图。
如果你喜欢我的文章,请关注,并转发、点赞和在看,这是对我莫大的鼓励!