Reputation: 157
I'm learning C Programming through "Learn C the Hard Way." I have am currently on Exercise 1, which can be found here: http://c.learncodethehardway.org/book/ex1.html
I understand the concept being covered, but don't understand the compiling process. While using the "make" command in the command line, why does this work:
$ make ex1
And this not work:
$ make ex1.c
I was actually just running the second command until a minute ago. I eventually figured it out though. Until I did, I kept getting this error message:
make: nothing to be done for 'ex1.c'
While this is a just a technicality, I would still like to know what's happening. Thanks :)
Upvotes: 7
Views: 2432
Reputation: 11
the argument to the make
tool is the name of the executable file that it
will help create for you. It should not have a .c
extension. You should have
written make ex1
only.
Upvotes: 1
Reputation: 753455
Both work; they just do different tasks.
make ex1.c
says "using the rules in the makefile plus built-in knowledge, ensure that the file ex1.c
is up to date".
The make
program finds ex1.c
and has no rules to build it from something else (no RCS or SCCS source code, for example), so it report 'Nothing to be done'.
make ex1
says "using the rules in the makefile plus built-in knowledge, ensure that the file ex1
is up to date".
The make
program finds that it knows a way to create an executable ex1
from the source file ex1.c
, so it ensures that the source file ex1.c
is up to date (it exists, so it is up to date), and then makes sure the ex1
is up to date too (which means 'file ex1
was modified more recently than ex1.c
). If you've edited ex1.c
since you last ran make
, it will do the compilation to make ex1
newer than ex1.c
. If the compilation fails, the file ex1
won't exist, so you'll get another recompilation next time too. And once it is up to date, then make
won't rebuild ex1
again until you modify the source again.
This is the way make
is designed to work.
Upvotes: 12
Reputation: 72271
The target to make
usually specifies what you want it to build or rebuild, not what you want it to use to build something else.
If you type ex1.c
(and there's no rule to auto-generate it), make essentially just answers "Yup, that file exists."
Upvotes: 4