erro fatal nenhum arquivo ou diretório [fechado]

0

Oi eu tenho um problema na linha terminal linux. Então eu tentei compilar um arquivo para .o assim

gcc -c palindrome.c

e o erro é

palindrome.c:2:21: fatal error: reverse.h: No such file or directory
compilation terminated.

O arquivo reverse.h de fato está no diretório porque eu copiei tudo do diretório lab2 para o laboratório 3. Então, por que ele está dizendo isso? Obrigado pela ajuda

cscstuff@ubuntu:~/inlab2$ ls -l
total 32
-rwxrwxr-x 1 cscstuff cscstuff 8784 Oct  1 08:26 main1
-rw-rw-r-- 1 cscstuff cscstuff  338 Oct  1 08:20 main1.c
-rw-rw-r-- 1 cscstuff cscstuff 1888 Oct  1 08:24 main1.o
-rw-rw-r-- 1 cscstuff cscstuff  204 Oct  1 08:26 reverse.c
-rw-rw-r-- 1 cscstuff cscstuff   84 Oct  1 08:19 reverse.h
-rw-rw-r-- 1 cscstuff cscstuff 1472 Oct  1 08:26 reverse.o
cscstuff@ubuntu:~/inlab2$ cd
cscstuff@ubuntu:~$ cd inlab3
cscstuff@ubuntu:~/inlab3$ ls -l
total 16
drwxrwxr-x 2 cscstuff cscstuff 4096 Oct  1 08:33 inlab2
-rw-rw-r-- 1 cscstuff cscstuff  247 Oct  1 09:21 main2.c
-rw-rw-r-- 1 cscstuff cscstuff  297 Oct 15 11:01 palindrome.c
-rw-rw-r-- 1 cscstuff cscstuff   51 Oct  1 08:34 palindrome.h
cscstuff@ubuntu:~/inlab3$ gcc -c palindrome.c
palindrome.c:2:21: fatal error: reverse.h: No such file or directory
compilation terminated.
cscstuff@ubuntu:~/inlab3$ 
    
por Kat Mi 15.10.2017 / 20:15

1 resposta

1

De inlab3

  • adicione -I../inlab2 ao compilador (por exemplo, gcc -I../inlab2 -c palindrome.c , isso dirá ao gcc para procurar em ../inlab2 para o arquivo de cabeçalho)

  • use #include "../inlab2/reverse.h" na linha de inclusão (isso fornecerá o caminho relativo para o arquivo de cabeçalho)

  • copie de inlab2 cp ../inlab2/reverse.h . (isso disponibilizará uma cópia do arquivo de cabeçalho em inlab3 )

por 15.10.2017 / 21:03