Skip to content
Advertisement

Makefile, add headers located in parent directory (Not allowed to move inside!)

JavaScript

prog.c

JavaScript

myheader1.h

JavaScript

myheader2.h

JavaScript

Looking for solution on how to add a header from parent directory I found this question. But it didn’t work for me and I am still getting error of not finding the header file.

No rule to make target ‘myheader1.h’, needed by ‘prog.o’. Stop.

makefile

JavaScript

What am I doing incorrect? and how to add the second header without making lines go extremely long or ugly?

Advertisement

Answer

JavaScript

This line says prog.o depends on two files, prog.c and myheader1.h. prog.c exists, but myheader1.h does not (at least not in the same directory).

It should be

JavaScript

Note:

  • ../myheader1.h in the list of prerequisites, not myheader1.h
  • headers should not be listed on the compiler command line at all
  • -c doesn’t really belong in CFLAGS
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement