I wonder why 'Makefile' demands dependency line in spite of a command line already has list of file. For example,

hello : main.o hello.o

        gcc -o main.o hello.o

The gcc command already contains main.o, hello.o. Writing dependency line looks inefficient.

  • 1
    I'm feeling you may have missed the point of make somewhat: it's primary advantage isn't just to blindly run a set of commands (shell scripts are perfectly good at that), but to work out which commands need to be run. It can't do that without dependencies. Feb 11, 2017 at 14:30

1 Answer 1


Yes, but it's the build rule that is unnecessary, not the dependency. It the dependencies that makes make tick, after all. The rule for building is also seriously wrong (will overwrite main.o rather than building hello).

Using the implicit rules, this may be shortened to just

hello: main.o hello.o

Or if you want an explicit make rule in addition to the dependency:

hello: main.o hello.o
    $(CC) -o $@ $<

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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