LogicalKip
LogicalKip

Reputation: 522

No rule to make something.o even though %.o is defined

I'm new to the forum, so I hope I'm doing things right.

I'm writing from scratch a Makefile for a C project. It was working at some point, then I tried to improve it a little (including separate folders), and I got the well-known error "No rule to make target "obj/autresFonctions.o", needed for "CUR"". Or similar, since it's not in english and I translated.

That seems quite weird since the rule I'm expecting to work is using %.o and should match anyhting. Thus I don't think it could be a typo.

Here is the Makefile :

EXE=prgm
CC=gcc

SRC_DIR=src
OBJ_DIR=obj
INCLUDE_DIR=include

_FICHIERS_H = autresFonctions.h calculPrealable.h constantes.h fonctionsAnnexes.h fonctionBoucles.h lectureFichiers.h main.h
FICHIERS_H = $(patsubst %, $(INCLUDE_DIR)/%, $(_FICHIERS_H))

_OBJ = autresFonctions.o calculPrealable.o fonctionsAnnexes.o fonctionsBoucles.o lectureFichiers.o main.o
OBJ = $(patsubst %, $(OBJ_DIR)/%, $(_OBJ))


FLAGS=-Wall -Wextra



CUR: $(OBJ)
    $(CC) -o $(EXE) $^

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(FICHIERS_H)
    $(CC) $(FLAGS) -c -o $@ $< 

clean:
    rm $(OBJ) $(EXE) 

I'm assuming it's the same for the others .o, because I also tried switching the first two .o in _OBJ , and I got the same error with calculPrealable.o

I'm just typing "make" when compiling, in order to get CUR, the main target. I'm located in the main directory, which contains include/ (with the .h), src/ (with the .c) and obj/ (empty).

EDIT : I forgot to say, but I'm using the usual GNU make.

Upvotes: 1

Views: 1625

Answers (1)

MadScientist
MadScientist

Reputation: 100856

The pattern rule only matches if ALL of the rule matches. It's not enough to just match the target: make must also be able to find (or make) the prerequisite pattern(s) and all other prerequisites listed in the rule.

If one thing doesn't match, then the rule doesn't match.

You can use make -d to see what files make is trying to build, and see which one doesn't exist and causes the rule to fail.

PS. This is all assuming you're using GNU make, which you don't say specifically.

Upvotes: 1

Related Questions