Reputation: 35734
I have a simple c program - hello_world.c
As you can tell by the file name i am very very new to c.
I would expect to do the following to compile:
make hello_world.c
But this gives an error message: make: Nothing to be done for hello_world.c.
If i just do make hello_world
it works i.e. without the extension.
Can someone explain why this is?
Upvotes: 5
Views: 7640
Reputation: 224844
make
takes a target as its argument. If you tell it you want to make hello_word.c
, it will look, see that that file already exists and has no dependencies, and will decide it's up to date - hence nothing to do.
When you say make hello_world
, make looks for hello_word
, can't find it, then looks for hello_world.o
, can't find it, then looks for hello_world.c
, finds it, and then uses its implicit rule to build hello_world
from it.
You can use make -d
to see the decisions make
is making along the way. Here's the example for make hello_world.c
- I've trimmed out a bunch to showcase the last part, which is what you care about:
...
Considering target file `hello_world.c'.
Looking for an implicit rule for `hello_world.c'.
...
No implicit rule found for `hello_world.c'.
Finished prerequisites of target file `hello_world.c'.
No need to remake target `hello_world.c'.
make: Nothing to be done for `hello_world.c'.
Then, for make hello_world
:
...
Considering target file `hello_world'.
File `hello_world' does not exist.
Looking for an implicit rule for `hello_world'.
Trying pattern rule with stem `hello_world'.
Trying implicit prerequisite `hello_world.o'.
Trying pattern rule with stem `hello_world'.
Trying implicit prerequisite `hello_world.c'.
Found an implicit rule for `hello_world'.
Considering target file `hello_world.c'.
Looking for an implicit rule for `hello_world.c'.
Trying pattern rule with stem `hello_world'.
...
No implicit rule found for `hello_world.c'.
Finished prerequisites of target file `hello_world.c'.
No need to remake target `hello_world.c'.
Finished prerequisites of target file `hello_world'.
Must remake target `hello_world'.
cc hello_world.c -o hello_world
...
Successfully remade target file `hello_world'.
Upvotes: 10
Reputation: 4353
"Make" is a tool that is used to build non-trivial projects with multiple source files. If all you want to do is compile a single C file, use the C compiler. cc
is usually available as the command-line name of the C compiler, though gcc
is also a common name (which may refer to the same compiler).
Upvotes: -2