[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LDADD and linker options like --whole-archive

From: Ralf Wildenhues
Subject: Re: LDADD and linker options like --whole-archive
Date: Wed, 19 Apr 2006 18:38:28 +0200
User-agent: Mutt/1.5.11

Hi Stefan,

* Stefan Puiu wrote on Wed, Apr 19, 2006 at 04:23:04PM CEST:
> I was considering to file this as a bug report, but I thought I'd
> first check on the list first. Sorry if this was already brought up
> (there's also a bug report which is somewhat similar to my problem -
> automake PR number 55).

Probably has.  But you are bringing up more than one point.

> So, my problem is that for some reason in our projects some libraries
> *have* to be linked in using a --whole-archive/--no-whole-archive wrap
> around them.

Have you ever considered using Libtool?  Its convenience archives would
be a portable alternative to --whole-archive.

> I also use --start-group/--end-group when I have to add a
> long list of libraries (dozens) and I don't want to waste time trying
> to put them in the right order.

An alternative to --start-group/--end-group portable also to non-GNU
binutils linkers would be to list all libraries more than once.  In
practice, twice is often sufficient, like so: -la -lb -lc -la -lb -lc.

But I'd not consider it clean design.  If all your libraries are not to
be installed, just built separately, and thus internal, then just make
them all convenience archives.  Then everything will be included in the
output, and you won't worry about order nor missing symbols.  If
libraries are to be installed and used by third parties, then you better
sit down and draw a graph which explains to your users how the libraries
depend upon each other.  The linking order follows naturally from that

> Now, how would we add those libraries to the linker options in my
> files?
> Option 1: add the directories to <binary>_LDFLAGS (-L<dir1> ...) and
> then the libraries with -l<lib1> ..., wrapped around with
> --whole-archive in <binary_LDADD>. However, this doesn't work, since
> you can't add linker options in <binary_LDADD>:
> linker flags such as `-Wl,--whole-archive' belong in `<binary>_LDFLAGS
> is the error message printed by automake when you try to do that. The
> same happens with --start-group/--end-group. This is also documented
> in the automake manual I have.

Note some things here:
- First, you can work around the error by substituting the flags at
  configure time, and thus hiding them from Automake
- Second, you should do that anyway, as they are not portable,
  and thus would better be conditionalized at configure time.

Note further that, if you are speaking of libraries built inside the
project, then the preferred way of adding them is

  binary_LDADD = ./libfoo.a

instead of
  binary_LDADD = -L. -lfoo

because the former will get Automake to output proper dependency
information.  (You could again use Libtool libraries instead to be
portable to w32 hosts here, where libraries may be called libfoo.lib.)

> Am I missing something, or is this setup as bad as it seems?

No.  It's just that your flags are not portable, and Libtool would seem
as the portable solution.  Note however that you will still have to
either clean up your library dependency tree, or announce the
duplication to libtool, should it not ignore it.

Please also note that libtool currently does not support position
dependent linker flags such as --whole-archive, --start-group,
--add-needed, --as-needed, or -Bstatic.  Lifting that restriction
is planned, as possible, at some point in the future.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]