1

Autotools knows about target_LDFLAGS and target_LDADD. The difference is that LDADD gets added later to the command line than LDFLAGS, and its the right place to put libraries (-lfoo). See also this question.

Now, I can set the environment variable LDFLAGS before running ./configure, and it is picked up. Is there something similar for LDADD? I want to do something like:

export LDADD="-lfoo"
./configure
make

and have -lfoo appear after all the object files while linking. I tried the above but it didn't work. LDFLAGS works, but puts the library at the wrong place. What can I do?

Community
  • 1
  • 1
jdm
  • 8,101
  • 9
  • 46
  • 90

1 Answers1

2

The autoconf manual suggests that these "-lfoo" options should be added to the LIBS variable, as described by ./configure --help.

You could have: AC_SUBST(target_LIBS, $LIBS) in configure.ac, and in Makefile.am :

target_LDADD = $(target_LIBS)

The ideal, of course, would be for the configure script to set target_LIBS automatically, if possible...

Brett Hale
  • 20,019
  • 2
  • 47
  • 81
  • Don't `AC_SUBST` the automake variables from the configure script, this is not how they should be used. – DanielKO Oct 11 '13 at 02:10
  • @DanielKO - `target_LIBS` is not an automake variable in this context. This is the correct way to pass configure-time values to automake. – Brett Hale Oct 11 '13 at 12:09
  • yes, using variables that look like automake variables by a few characters is **indeed** the way to do it. Use target_LDFLAG too, and live more intensely. – DanielKO Oct 11 '13 at 15:41
  • I got confused, you gave bad advice. And you don't have a sense of humor. He was asking about changing the invocation of configure anyways, not editing it. – DanielKO Oct 11 '13 at 16:14