I am writing a Makefile to run my c program.
The directory and files are shown below,
And here is my codes in Makefile
all: perimeter.o main.c
gcc -o program main.c perimeter.o
perimeter.o: perimeter.c perimeter.h
gcc -c perimeter.c
clean:
find ./ -executable -delete
test: tests
tests: test.o
gcc -o tests test.o
test.o: ./tests/test.c
gcc -c ./tests/test.c -I..
However, the header files can not be found
Then I tried...
test.o: ./tests/test.c perimeter.h
gcc -c ./tests/test.c -I..
and
test.o: ./tests/test.c perimeter.h
gcc -c ./tests/test.c -I ../
and
test.o: ./tests/test.c perimeter.h
gcc -c ./tests/test.c
All Failed
So I think -I..
is not work.(I also tried -I ../
)
How to solve this problem?
The script expects the CWD to be the directory containing Makefile
(since it uses perimiter.c
and ./tests/test.c
), so perimiter.h
is in the CWD, so
gcc -c ./tests/test.c -I..
should be
gcc -c ./tests/test.c -I.