前提:在 xx/common/文件夹下创建fs_testinc.h头文件,在xx/public/文件夹下创建相同名fs_testinc.h头文件;
在xx/core/fs_core.c下 include “fs_testinc.h”,此时到底是包含xx/common/文件夹下还是xx/public/文件夹下的fs_testinc.h呢?
经过测试实验,规则如下:
当makefile或者SConscript下定义了gcc包含文件夹路径编译选项,以SConscript为例:
如 :
os.path.join(cwd, 'public'),
os.path.join(cwd, 'common')
包含顺序,则会选择public文件夹下的fs_testinc.h
反之如:
os.path.join(cwd, 'common')
os.path.join(cwd, 'public'),
包含顺序,则会选择'common'文件夹下的fs_testinc.h
结论,当两个文件夹均被编译器包含为头文件查找路径,查找顺序为优先先包含的头文件查找路径!
故include “fs_testinc.h”包含优先顺序如下:
当与.c文件在相同文件夹下则第一优先查找包含;
当与.c文件在不相同文件夹下,则以makefile或者SConscript下包含文件夹路径优先顺序来查找,找到了则停止查找。
如何解决include “fs_testinc.h”不确定问题呢?
如:include “../ public/xxx.h”则可确定是包含public/文件夹下的xxx.h,而不是common文件夹下的xxx.h