user9091498
user9091498

Reputation: 41

Make file in C giving fatal error

I am trying to create a makefile in C but i am facing some issues. I have my main .c, one .c which keeps the functions implementations and one .h which keeps the functions declarations. When i try to run the makefile, i get a fatal error. here is my makefile:

INCL   = prog.h
SRC    = prog.c prog_fun.c
OBJ    = $(SRC:.c=.o)
EXE    = prog


CC = gcc  
CFLAGS  = -c
RM      = rm -rf

all: prog

prog: prog.o prog_fun.o
    gcc -o prog prog.o prog_fun.o 

prog.o: prog.c 
    gcc -c prog.c

prog_fun.o: prog_fun.c prog.h
    gcc -c prog.c

clean:
    $(RM) $(OBJ) $(EXE)

The error i get is this:

gcc -c prog.c
prog.c:11:19: fatal error: prog.h: No such file or directory
compilation terminated.
Makefile:17: recipe for target 'prog.o' failed
make: *** [prog.o] Error 1

Can anyone please help me with this?

Upvotes: 1

Views: 736

Answers (1)

Achal
Achal

Reputation: 11921

What you are trying to do by using this

prog_fun.o: prog_fun.c header.h

It should be only

prog_fun.o: prog_fun.c 

Modify your make file as

xyz@xyz-PC:~$ vi makefile 
INCL   = header.h
SRC    = prog.c prog_fun.c
OBJ    = $(SRC:.c=.o)
EXE    = prog


CC = gcc
CFLAGS  = -c
RM      = rm -rf

all: prog
prog: prog.o prog_fun.o
        gcc -o prog prog.o prog_fun.o 
prog.o: prog.c
        gcc -c prog.c header.h
prog_fun.o: prog_fun.c
        gcc -c prog_fun.c header.h

clean:
        $(RM) $(OBJ) $(EXE)

next run it

xxyz@xyz-PC:~$ make
gcc -c prog.c header.h
gcc -c prog_fun.c header.h
gcc -o prog prog.o prog_fun.o 

I hope it will work now and make sure indention is correct(not manual spaces, it should be tab key)

Upvotes: 1

Related Questions