user13500922
user13500922

Reputation:

makefile error "No rule to make target" how to solve it?

what's wrong with my makefile?

CC = gcc
OBJS = main.o map.o extended_map.o election.o utilities.o
EXEC = election
DEBUG_FLAG = -DNDEBUG
COMP_FLAG = -std=c99 -Wall -pedantic-errors -Werror

$(EXEC) : $(OBJS)
    $(CC) $(DEBUG_FLAG) $(OBJS) -o $@
main.o: main.c map.h election.h test_utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
map.o: map.c map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
extended_map.o: extended_map.c extended_map.h map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
election.o: election.c election.h map.h extended_map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
utilities.o: utilities.c utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
clean:
    rm -f $(OBJS) $(EXEC)

I am running the following command on linux:

-bash-4.2$ ls
election.c  extended_map.c  main.c  makefile  mtm_map           utilities.c
election.h  extended_map.h  main.o  map.h     test_utilities.h  utilities.h
-bash-4.2$ make
make: *** No rule to make target `map.c', needed by `map.o'.  Stop.
-bash-4.2$

map.c exists inside a folder named mtm_map inside the current folder

Upvotes: 0

Views: 2769

Answers (1)

Chad Miller
Chad Miller

Reputation: 1475

You told make how to build "map.o" out of "map.c", but you don't have "map.c". You have "mtm_map/map.c".

You probably want something like

CC = gcc
OBJS = main.o mtm_map/map.o extended_map.o election.o utilities.o
EXEC = election
DEBUG_FLAG = -DNDEBUG
COMP_FLAG = -std=c99 -Wall -pedantic-errors -Werror

$(EXEC) : $(OBJS)
    $(CC) $(DEBUG_FLAG) $(OBJS) -o $@
main.o: main.c map.h election.h test_utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
mtm_map/map.o: mtm_map/map.c map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
extended_map.o: extended_map.c extended_map.h map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
election.o: election.c election.h map.h extended_map.h utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
utilities.o: utilities.c utilities.h
    $(CC) -c $(DEBUG_FLAG) $(COMP_FLAG) $*.c
clean:
    rm -f $(OBJS) $(EXEC)

Upvotes: 1

Related Questions