When I use make, it says
gcc -I./header -c -g main.c
gcc: error: main.c: No such file or directory
My makefile is here:
vpath %.c ./src
vpath %.h ./header
CC = gcc
FLAG = -I./header -c -g
objects = main.o a.o b.o
app: ${objects}
${CC} -o app ${objects}
main.o: main.c command.h
${CC} ${FLAG} main.c
a.o: a.c command.h
${CC} ${FLAG} a.c
b.o: b.c command.h
${CC} ${FLAG} b.c
clean:
-rm *.o app
.PHONY: clean
and files are stored like this:
.
|-- header
| `-- command.h
|-- Makefile
`-- src
|-- a.c
|-- b.c
`-- main.c
What’s wrong with the Makefile?
You should use automatic variables instead of hard coded values for file names in recipes:
This allows Make to insert the right file names found in
vpath: