5

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?

0

2 Answers 2

10

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'.
1
  • Oh so when i call make it is looking at the files in the current directory Jun 7, 2013 at 17:12
-2

"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).

2
  • 1
    make is very convenient even for single-file projects. The implicit rules allow you to pass compiler flags easily and consistently via environment variables, for example.
    – Carl Norum
    Jun 7, 2013 at 17:14
  • We may have to agree to disagree. I'll admit that I'm pretty much an un-fan of make at this point.
    – danfuzz
    Jun 7, 2013 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.