错误:没有这样的文件或目录-C [英] Error: no such file or directory - C
问题描述
解释了此评论后,
/***************** arrayImpl.c **************/
#include"list/list.h"
#if defined(ARRAY)
....
#endif
我写了 #include list / list.h
在 ./ Computing / list / arrayImpl.c
中使用 Computing测试
程序,显示在此处。计算/列表
ADT /testList.c
I wrote #include"list/list.h"
in ./Computing/list/arrayImpl.c
for testing Computing/list
ADT using Computing/testList.c
program, shown here.
但是 list / list.h找不到
,如下所示, list / list.h
.c
But list/list.h
could not be found by list/arrayImpl.c
, as shown below,
PC ~/code_practice/Computing
$ gcc -Wall -g -DARRAY ./list/*.c testList.c -o testList
./list/arrayImpl.c:3:22: fatal error: list/list.h: No such file or directory
compilation terminated.
./list/linkedListImpl.c:3:22: fatal error: list/list.h: No such file or directory
compilation terminated.
在发表评论后,我如何理解此错误?我误解了吗?
How do I understand this error, after following that comment? Did I mis-interpret?
推荐答案
list.h
在与包含它的c文件相同的目录。
list.h
is in the same directory as the c files which include it. When you do
#include "list/list.h"
编译器尝试在包含路径+ / list
中查找文件。例如,它将查找不会退出的 list / list / list.h
。
the compiler tries to find the file in include path + /list
. For instance, it will look for list/list/list.h
which doesn't exit.
那又如何呢?将工作将更改为 #include list.h
So what would work would be changing to #include "list.h"
OR
使用 -I将当前目录添加到命令行。
这样, list / list.h
gcc -Wall -g -I. -DARRAY ./list/*.c testList.c -o testList
来自 gcc搜索路径文档
-I。 -I-完全不同于没有-I选项,并且对于<>包括包括没有特殊选项的get不会导致相同的行为。 -I。在编译器的当前工作目录中搜索头文件。可能与包含当前文件的目录相同,也可能不同。
在任何包含路径的地方都没有提及包含从中启动gcc的当前目录。
It's not mentioned anywhere that include path contains the current directory, from which gcc was started.
这篇关于错误:没有这样的文件或目录-C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!