Daniel Guldberg Aaes
Daniel Guldberg Aaes

Reputation: 292

Error in makefile, compile multiple C files

I am trying to create a makefile so I can compile multiple C files. this makefile doesn't work as expected and do only compile ex1 when i run make alland gives error about ex3 (See error log)

CFLAGS=-Wall -g


all:
    make ex1
    make ex3

clean:
    rm -f ex1
    rm -f ex3

Error:

make all
make ex1
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
cc -Wall -g    ex1.c   -o ex1
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make ex3
make[1]: Entering directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
make[1]: *** No rule to make target 'ex3'.  Stop.
make[1]: Leaving directory '/home/daniel/ownCloud/code/Learn C the hard way/Make'
Makefile:5: recipe for target 'all' failed
make: *** [all] Error 2

Upvotes: 1

Views: 83

Answers (1)

simpel01
simpel01

Reputation: 1782

it is a bad idea recursively invoke make. You should write your makefile as follows:

CFLAGS=-Wall -g

all: ex1 ex3

clean:
    rm -f ex1 ex3

Upvotes: 1

Related Questions