title: GCC Makefile Error : No rule to make target 'put.h', needed by 'straps.o'. Stop
body: <p>I am trying to run my makefile using make run but its getting some errors : &quot;No rule to make target 'put.h', needed by 'straps.o'. Stop&quot;. The error is about GCC can't find the headers file(put.h) when running makefile with the text below :</p>
  <p>In kernel directory's Makefile</p>
  <pre><code>VPATH=../../include
  all : straps.o entry.o head.o
  straps.o : straps.c put.h
       $(GCC) -c straps.c $(CFLAG)
  entry.o : entry.S 
       $(GCC) -c entry.S $(CFLAG) 
  head.o : head.S 
       $(GCC) -c head.S $(CFLAG)
  </code></pre>
  <p>(straps.c include&quot;put.h&quot; so i need to include put.h)
  I am trying to include headers file in the gcc command line (by using $(GCC) -c straps.c $(CFLAG) -I../include) but still not working. Can anyone explain why I am getting this error and suggest a fix solution if possible. Thank you</p>
  <p>My file list</p>
  <pre><code>Linux
  ├── arch
  │   └── riscv
  │       ├── kernel
  │       │   ├── entry.S
  │       │   ├── head.S
  │       │   ├── Makefile
  │       │   ├── straps.c
  │       │   └── vmlinux.lds
  │       └── Makefile
  ├── include
  │   ├── put.h
  │   └── test.h
  ├── init
  │   ├── main.c
  │   ├── Makefile
  │   └── test.c
  ├── lib
  │   ├── Makefile
  │   └── put.c
  └── Makefile
  </code></pre>
  <p>Main Makefile gives the variable as below :</p>
  <pre><code>export
  CROSS_= riscv64-unknown-elf-
  AR=${CROSS_}ar
  GCC=${CROSS_}gcc
  LD=${CROSS_}ld
  OBJCOPY=${CROSS_}objcopy
  ISA ?= rv64imafd
  ABI ?= lp64
  INCLUDE = -I ../include
  CF = -g -O3 -march=$(ISA) -mabi=$(ABI) -mcmodel=medany -ffunction-sections -fdata-sections -nostartfiles -nostdlib -nostdinc -static -lgcc -Wl,--nmagic -Wl,--gc-sections
  CFLAG = ${CF} ${INCLUDE}
  </code></pre>
  <p>***Solution :
  The kernel directory's Makefile Updated as below (refers to the answer given in the post below):</p>
  <pre><code>VPATH = ../../../include
  CFLAG += -I../../../include
  all : straps.o entry.o head.o
  straps.o : straps.c put.h
          $(GCC) -c straps.c $(CFLAG)
  entry.o : entry.S
          $(GCC) -c entry.S $(CFLAG)
  head.o : head.S
          $(GCC) -c head.S $(CFLAG)
  </code></pre>