2016-12-23 3 views
1

comment을 해석 한 후, 오류 : 그런 파일이나 디렉토리 - C

/***************** arrayImpl.c **************/ 

#include"list/list.h" 

#if defined(ARRAY) 
.... 
#endif 

나는 here 표시 Computing/testList.c 프로그램을 사용 Computing/list ADT를 테스트하기 위해 ./Computing/list/arrayImpl.c#include"list/list.h"을 썼다.

그러나 list/list.h 다음과 같이

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. 

어떻게이 오류를 이해 할, 그 주석을 수행 한 후, list/arrayImpl.c에 의해 찾을 수 없습니다? 내가 잘못 해석 했습니까?

+0

@ Jean-FrançoisFabre 'arrayImpl.c'코드 – overexchange

답변

4

list.h은 포함하는 c 파일과 동일한 디렉토리에 있습니다. 당신이

#include "list/list.h" 

을 수행 할 때 컴파일러는 경로 + /list 포함에서 파일을 찾습니다. 예를 들어, 종료하지 않는 list/list/list.h을 찾습니다.

그래서 -I. 그렇게 list/list.h이있는 경로를 포함하여 명령 줄에 현재 디렉토리를 추가 #include "list.h"

또는

로 변경 될 작동합니다.

gcc -Wall -g -I. -DARRAY ./list/*.c testList.c -o testList 

gcc search path documentation

-I. -I- is not the same as no -I options at all, and does not cause the same behavior for ‘<>’ includes that ‘""’ includes get with no special options. -I. searches the compiler's current working directory for header files. That may or may not be the same as the directory containing the current file.

에서 경로가 GCC가 시작된 현재 디렉토리를 포함 포함이 어디 언급 아니에요.

+0

나는 많은 테스트를했고 주석은 잘못되었다. 내 편집을 확인하십시오, 설명서는 현재 디렉토리에 대해 이야기하지 않습니다. –

+0

gcc doc : * 현재 파일을 포함하는 디렉토리와 같을 수도 있고 그렇지 않을 수도 있습니다. *이 문맥에서 현재 파일'arrayImpl.c '를 포함하고있는'list' 디렉토리를 의미합니다. 그 맞습니까? – overexchange

+0

예, 정확하게. 현재 컴파일 된 파일 dir은 현재 컴파일 된 파일 dir을 포함하지 않는다는 것을 알려주는'<>'를 사용하여 파일을 포함하지 않는 한이 컴파일만을위한 컴파일러 검색 경로에 자동으로 추가됩니다. –

1

include 파일 디렉토리 "list"를 추가해야합니다.

https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

gcc -Wall -g -DARRAY ./list/*.c testList.c -I list -o testList

그리고 당신은 "사용법 #include"목록/list.h에서 "목록"을 제거해야합니다 "는 모든에서 검색하는 컴파일러에 말할 것을 쓸 때 때문입니다. 파일 디렉토리를 포함" 목록/list.h. "그러나"list.h는

#include "list.h" 

당신은 그렇게 할 수 있습니다. 목록 "필요하지 않다"그래서. "목록"에 "그러나 그것은 추한

#include "../list/list.h" 
+0

으로 내 쿼리를 편집했습니다. $ gcc -Wall -g -DARRAY ./list/*.c testList.c -I list -o testList'는 동일한 오류를 나타냅니다. – overexchange

+0

@ overexchange는 나의 나쁜 것을 고쳤다 – Stargateur

관련 문제