Issue
My project looks like
project
│
├── bin
│ └── makefile
├── include
│ ├── defs.h
│ ├── func.h
│ └── print.h
└── src
├── func.c
├── main.c
└── print.c
and makefile is
OBJS = func.o print.o main.o
TARGET = program
INCLUDE_DIR = ../include
SRC_DIR = ../src
vpath %.h $(INCLUDE_DIR)
vpath %.c $(SRC_DIR)
.PHONY: clean
$(TARGET): $(OBJS)
$(CC) $^ -o [email protected]
$(OBJS): defs.h
clean:
rm $(OBJS) $(TARGET)
but when i type "make" i get this
cc -c -o func.o ../src/func.c
cc -c -o print.o ../src/print.c
cc -c -o main.o ../src/main.c
../src/main.c:1:10: fatal error: func.h: Нет такого файла или каталога
#include "func.h"
^~~~~~~~
compilation terminated.
make: *** [<встроенное>: main.o] Ошибка 1
(Sorry for russian text, it's something like there is no such file or directory)
I know that I can write #include "../include/func.c" but is there other solutions?
Solution
I already solved this, now my makefile looks like this:
OBJS = func.o print.o main.o
TARGET = program
INCLUDE_DIR = ../include
SRC_DIR = ../src
vpath %.h $(INCLUDE_DIR)
vpath %.c $(SRC_DIR)
.PHONY: clean
$(TARGET): $(OBJS)
$(CC) $^ -o [email protected]
main.o: main.c defs.h
$(CC) -c -o [email protected] -I$(INCLUDE_DIR) $<
$(OBJS): defs.h
clean:
rm $(OBJS) $(TARGET)
Answered By - Maks Ternovoy Answer Checked By - David Goodson (WPSolving Volunteer)