Make - nothing needs to be done - only with the file extension

I have a simple c program - hello_world.c

As you can tell by file name, I am very new to c.

I would like to do the following for compilation:

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, that is, without an extension.

Can someone explain why this is?

+4
source share
2 answers

make takes an argument as an argument. If you say that you want to do hello_word.c , it will look, look that this file already exists and has no dependencies, and decides its relevance - therefore, there is 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 how make decisions are made. Here is an example for make hello_world.c - I cut the heap to demonstrate the last part 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'. 
+5
source

"Make" is a tool that is used to create non-trivial projects with multiple source files. If all you want to do is compile a single C file, use the C compiler. cc usually available as the command line name of the C compiler, although gcc also a common name (which may refer to the same compiler).

-1
source

Source: https://habr.com/ru/post/1485087/


All Articles