Karel Zak wrote on Wed, Aug 01, 2018 at 01:17:29PM +0200:
Well, --as-needed is workaround and nothing else. The real problem is
mess in makefiles and .pc (pkg-config) files.
It would be better to use --as-needed for testing purpose only, and
ask maintainers why the result with --as-needed is different.
Wearing a lib developer hat, I don't see how you can make a .pc that
doesn't overlink if you provide something a bit entangled with other
The problem is that if your headers use any sub-lib type you need to add
that lib in Requires: so that --cflags will pull that lib's include
path; and that will in turn add that sub-lib to the linked libs even if
the program likely doesn't care about it (either because they didn't
even use that part of your lib, or because all uses of that lib will be
done through your own anyway so it wasn't required in the first place)
This isn't obvious if you only support systems like fedora where most
packages include dirs are standard to /usr/include but if you want to
start supporting people working with dependencies in subdirs or distros
like nixos that will have one include directory per dependency, you
really need to put every external headers your depend on as 'Requires'.
Unless you can tell pkgconfig "take all of these dependencies for
--cflags but not for --libs" I do not see how this can be improved, and
that's where --as-needed is helpful.
It's not the ideal solution, but I don't have anything better right now,
and pkg-config is by far not the worst solution to handling