Lostttt
Lostttt

Reputation: 9

Makefile does not compile the current changes .c file

I am writing a makefile for my program, but whenever i do make in my pwd, it is not showing with the latest changes made in .c file. What am i doing wrong with this ?

web : mweb.o
    gcc -o bin/web bin/web.o 
mweb.o : src/web.c
    gcc -c -std=c99 -Wall src/web.c -o bin/web.o
clean:
    rm -f web 

Upvotes: 0

Views: 469

Answers (1)

MadScientist
MadScientist

Reputation: 100836

It's always wrong for your makefile rules to create files that are not the identical pathname of the target you provided in your rule. So:

<target>: ...
        <command>

The <command> must create the file named by <target>.

Here, your <target> in the first rule is web, but the compile command you gave creates the file bin/web. Your <target> on the second rule is mweb.o but the compile command creates the file bin/web.o.

That cannot work.

The best thing to do is use make's $@ automatic variable: those are set by make and always contain the files that make expects you to create.

CFLAGS = -std=c99 -Wall

bin/web : bin/mweb.o
        $(CC) $(CFLAGS) -o $@ $^ 
bin/mweb.o : src/web.c
        $(CC) -c $(CFLAGS) $< -o $@
clean:
        rm -f web 

Upvotes: 2

Related Questions