Reputation: 844
Learning C the Hard Way, coding up my first makefile. The makefile is in the directory with the C files "ex1.c" and ex3.c".
make ex1
compiles an executable "ex1" correctly. The Makefile contains:
all:
ex1
ex3
but calling "make" returns error
make: ex1: No such file or directory.
make: *** [all] Error 1
Why can make
find the source code when specified as an arg but not when specified by the makefile?
Upvotes: 2
Views: 148
Reputation: 80931
This snippet of makefile
all:
ex1
ex3
is telling make about one target all
and that that target has two lines of recipe to run when the all
target is requested.
So when you run make all
(or make
when all
is the first/default target) make tries to run ex1
and ex3
as shell commands. Which clearly fails since they haven't been built yet.
Assuming you meant to tell make to build the ex1
and ex3
targets what you meant was
all: ex1 ex3
That all said for simple ex1.c
-> ex1
compilation you don't even need a makefile at all. Which is why the book doesn't bother telling you to create one yet.
Upvotes: 3