Subject: bug#78411: LDADD vs. LDFLAGS

From: Bruno Haible <[email-masked]>
Date: Tue, 13 May 2025 18:59:20 +0200

The first paragraph in
https://www.gnu.org/software/automake/manual/html_node/Linking.html
can be interpreted in a misleading way:

  "If you need to link against libraries that are not found by configure,
   you can use LDADD to do so. This variable is used to specify additional
   objects or libraries to link with; it is inappropriate for specifying
   specific linker flags; you should use AM_LDFLAGS for this purpose."

Last week, I interpreted this as "objects or libraries" being *.o, *.a,
and *.la files. And "linker flags" as including -L and -l options.
And I concluded that I should specify the -L and -l options in
*_LDFLAGS, not in *_LDADD, variables.

But that would not work because of these Automake generated rules
and variables:

LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
test_bind_LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(test_bind_LDFLAGS) $(LDFLAGS) -o $@

test-bind$(EXEEXT): $(test_bind_OBJECTS) $(test_bind_DEPENDENCIES) $(EXTRA_test_bind_DEPENDENCIES)
        @rm -f test-bind$(EXEEXT)
        $(AM_V_CCLD)$(LINK) $(test_bind_OBJECTS) $(test_bind_LDADD) $(LIBS)

Here's a proposed slight rewording that avoids this ambiguity.

>From 7434f6ebecc536bf79a61f3746253a6618ab9d76 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email-masked]>
Date: Tue, 13 May 2025 18:57:00 +0200
Subject: [PATCH] doc: Clarify where to put -L and -l options.

* doc/automake.texi (Linking): Clarify that -L and -l options belong in LDADD.
---
 doc/automake.texi | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/doc/automake.texi b/doc/automake.texi
index bdd615e2d..3cbbff250 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -4946,9 +4946,12 @@ and Lex}.
 
 If you need to link against libraries that are not found by
 @command{configure}, you can use @code{LDADD} to do so.  This variable is
-used to specify additional objects or libraries to link with; it is
-inappropriate for specifying specific linker flags; you should use
-@code{AM_LDFLAGS} for this purpose.
+used to specify additional objects or libraries to link with.
+Libraries to link with can be indicated either as file names or
+through @code{-L} and @code{-l} options.
+
+For other linker options (not @code{-L} or @code{-l}), @code{LDADD}
+is inappropriate.  You should use @code{AM_LDFLAGS} for this purpose.
 @vindex LDADD
 @vindex AM_LDFLAGS
 
-- 
2.43.0