See the GNU manual ( info make ), section 10.2 . It has a directory of implicit rules, i.e. Rules in which you do not need to explicitly specify commands. Like @GregHewgill, the "implicit assembly rule" Single Object Linking "builds N from No , but the name must match. Thus, you can name your executable file as your object file, in which case
test:
or (more standard as it defines the purpose of all )
all : test
quite enough. You can also write a rule explicitly, as described in Greg Hewgill. In this case, the standard rule:
$(CC) $(LDFLAGS) No $(LOADLIBES) $(LDLIBS)
Include LDFLAGS and LDLIBS in your Makefile, this will make life easier for users.
(sic: I think LOADLIBES is really LOADLIBS, and the author skipped -o ).
In general, I would recommend autoconf and automake instead of manual files. Provides you with a set of Makefile functions for very little work.
source share