I'm trying to use GCC (linux) with a makefile to compile my project. I get the following error
"No rule to make target 'output/src/main.o', needed by 'test'. Stop."
This is the makefile:
COMPILE_PREX ?=
CC = $(COMPILE_PREX)gcc
SOURCE = $(wildcard src/*.c)
OBJS = $(addprefix ./output/, $(patsubst %.c, %.o, $(SOURCE)))
INCLUDES = -I ./src
CFLAGS += -O2 -Wall -g
LDFLAGS += -lpthread
TARGET = test
$(TARGET): $(OBJS)
$(CC) $(OBJS) $(LDFLAGS) -o $(TARGET)
%.o: %.c
@mkdir -p ./output
$(CC) $(CFLAGS) $(INCLUDES) -o $(addprefix ./output/, $@) -c $<
clean:
rm -rf ./output
%.o: %.c
rule does not create$@
(which you promised), but./output/$@
(which is the lie). – Jens*.o
to./output/
? – corey changoutput/%.o: src/%.c
work? This also needs$(CC) .... -o $@ -c $<
. – Jens