I'm trying to setup an automake project that uses a mix of libtool libraries and exectuables, and I'm having a hard time grokking the automake documentation, esp. as relates to telling the compiler to link against.
So can someone explain the differences between LDADD
and LIBADD
?
Things like:
- when is one used over the other,
- which one takes
-lname_of_library
style values vs. direct filenames, etc.
Whenever I try to read the relevant documentation, it seems like it assumes that I know things that I don't.
As mentioned in one of the books,
LDADD
is ADDitional linker(LD) items - i.e. items that are added when performing linking. This would be, for example, when producing programs.LDADD
can specify:lib/libfudge.la
-lm
, or/lib/libmagicalwonderland.a
-L/opt/lib -lmagical
They are in order of preference - Using the last two is just asking for trouble as they're pointing at things that may or may not be present.
LIBADD
is to specify ADDitional LIBraries to use. This is used when building a library to specify that additional libraries are needed in order to build or make use of the library. You'll see it specified as something likelibfred_la_LIBADD =
. It can be used to specify libtool libraries, or system libraries and will place these libraries into the resulting libtool.la
for the library so when it comes to linking against the library you get all the appropriate libraries brought along.You should only specify libraries to link, so, for example, my library
libfred.la
depends on some math routines i.e. it depends onlibm
. When I'm specifying the additional libraries for the library, I state:This dependency is encoded when I build the library, and gets passed on to consumers of the library as well.
The rule of thumb is:
Use the
LIBADD
primary for libraries, andLDADD
for executables. If you were building a libtool librarylibfoo.la
, that depended on another librarylibbar.la
, you would use:If you had other non-libtool libraries, you would also add these with
-L
and-l
options:Typically, you would use the configure script to find these extra libraries, and use
AC_SUBST
to pass them with:For a program, just use
LDADD
:Sometimes the boundaries are a bit vague.
$(EXTRA_FOO_LIBS)
could have been added tomyprog_LDADD
. Adding dependencies to a libtool (.la
) library, and usinglibtool
do all the platform-specific linker magic, is usually the best approach. It keeps all the linker metadata in the one place.