c/c ++:找不到头文件 [英] c/c++ : header file not found
问题描述
一些头文件存在于/src/dir1/
中(例如: ah
, bh
, ch
等等).我的源文件位于/src/dir2/file.cpp
中.我使用了/src/dir1/
中存在的一些头文件,但是在编译过程中出现了类似 header file not
的错误.
Some header files are present in /src/dir1/
(eg: a.h
, b.h
, c.h
etc). My source file is present in /src/dir2/file.cpp
. I used some header files that are present in /src/dir1/
but during compilation I got errors like header file not found
.
然后我更改了包含路径,例如 #include"../src/dir1/ah"
,然后 file.cpp
中的错误消失了,但是我得到了/src/dir1
中存在的头文件中的> not found 错误.因为我包含了标有 ah
的头文件,所以该 ah
包含了/src/dir1/
中存在的其他一些头文件(例如>
ch
出现在 ah
中.)
Then I changed the include path like #include "../src/dir1/a.h"
, then error is gone in file.cpp
but I get not found
error in the headers files that are present in /src/dir1
. Because I included the header file say a.h
, that a.h
included some other header files that are present in /src/dir1/
(say b.h
and c.h
present in a.h
).
如何在/src/dir2/file.cpp
中添加头文件( ah
),以便它不要求修改头文件中的包含路径出现在/src/dir1/
中?
How to add the header file (a.h
) in /src/dir2/file.cpp
so that it should not ask to modify the include path in the header files that are present in /src/dir1/
?
注意:我正在使用 scons
进行构建.
Note: I am using scons
to build.
推荐答案
您可以使用 gcc
的 -I
命令行参数将目录添加到包含文件搜索路径中:
You can add directories to the include file search path using the -I
command line parameter of gcc
:
gcc -I/src/dir1 file.cpp
这篇关于c/c ++:找不到头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!