In the GNU make manual 0.77 as found at
https://www.gnu.org/software/make/manual/make.html
the implicit rule for linking is, as given in Section 10.2:
n is made automatically from n.o by running the C compiler to
link the program. The precise recipe used is
‘$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)’.
There is no $(CFLAGS). But examples given earlier in the manual could
make the user think that it is present in the implicit rule.
Section 4.4.2 contains the example
objects = *.o
foo : $(objects)
cc -o foo $(CFLAGS) $(objects)
This is misleading because $(CFLAGS) is not used in the implicit rule.
In Section 6.6:
CFLAGS += -pg # enable profiling
is a bad advice, as the gcc man page says:
-pg Generate extra code to write profile information suitable for the
analysis program prof (for -p) or gprof (for -pg). You must use
this option when compiling the source files you want data about, and
you must also use it when linking.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
while CFLAGS is *not* used when linking.
In Section 6.14, about .EXTRA_PREREQS:
myprog: myprog.o file1.o file2.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LDLIBS)
and ditto in the subsequent examples.
Again, this is inconsistent with the implicit rule.
In Section 10.1:
foo : foo.o bar.o
cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
Same issue.
BTW, there should be an advice on what to do with options that are
needed both for C compilation and for linking (when GNU Automake
is not used, as Automake adds $(CFLAGS) for linking), like -pg,
-pthread, and sanitizer options.
--
Vincent Lefèvre <[email protected]> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)