Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Not work when use -I(capital i) in gcc in makefile

I am writing a Makefile to run my c program.

The directory and files are shown below,
enter image description here

And here is my codes in Makefile

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

enter image description here

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?

>Solution :

The scripts expects the CWD to be the directory contains 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.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading