[sword-devel] About what gets linked.....

Dmitrijs Ledkovs dmitrij.ledkov at gmail.com
Fri May 22 16:09:20 MST 2009


I did some digging and analysis about that link flags are added while
building libsword.

For libcurl currently `curl-config --libs` is used. On my machine
(Ubuntu jaunty) this command emits following:

$ curl-config --libs
-lcurl -lidn -llber -lldap -lrt -lgssapi_krb5 -lgssapi_krb5 -lz -lgnutls


Similarly with libicu - currently `icu-config --ldflags` is used which
on my machienve emits:

$ icu-config --ldflags
-lm -L/usr/lib -licui18n -licuuc -licudata -lm

I've used dpkg-shlibdeps which checks executables / libraries for
symbols they are using and what they are linked against.

And it does confirm that not all of these libraries are actually used

dpkg-shlibdeps: warning: dependency on libgcrypt.so.11 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libtasn1.so.3 could be avoided
if "debian/tmp/usr/lib/libsword.so" were not uselessly linked against
it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libicuio.so.38 could be avoided
if "debian/tmp/usr/lib/libsword.so" were not uselessly linked against
it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libidn.so.11 could be avoided
if "debian/tmp/usr/lib/libsword.so" were not uselessly linked against
it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libldap_r-2.4.so.2 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on liblber-2.4.so.2 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on librt.so.1 could be avoided if
"debian/tmp/usr/lib/libsword.so" were not uselessly linked against it
(they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libicudata.so.38 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libgnutls.so.26 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).
dpkg-shlibdeps: warning: dependency on libgssapi_krb5.so.2 could be
avoided if "debian/tmp/usr/lib/libsword.so" were not uselessly linked
against it (they use none of its symbols).

There are a few solutions on how to reduce amount of libraries that are linked.

1) Curl. Instead of using curl-config to use PKG_CHECK_MODULES macro
which is using information provided by the upstream in their
libcurl.pc
Cause according to libcurl.pc for a shared library build it will only
add -lcurl flag.

2) Icu. The option I see is to filter the output such that libicuio
and libicudata are not linked. (although some of the code suggest that
in the past these were explicitly added)

In addition to library all of these link flags are passed to all of
the utilities. Although most of the utilities are using these headers.
So I would in addtion suggest to reset / override link flags in the
utilities/Makefile.am to make sure that they link in only what they
need (e.g. zlib for a couple of them)

I've tried to create a patch to build system to fix some of these but
i didn't quite succeed. The only piece I did come up with is a work
around to patch ltmain.sh such that it accepts --as-needed option.
This results in ld thinking and not linking a library if it is not
used by executable. Such patch can be applied to a tarball but I can't
see a way to keep it constant even after "autogen.sh". And again
--as-needed is just a workaround cause the real reason is that
curl-config and icu-config are outputing too many libraries.

I really would love to have these "extra" dependencies libraries to be
dropped from debian packages. I can put together packages of sword
with "--as-needed" flag for some more testing but I really hope that
it could be sorted out the correct way.


Some references:

3 - has example how to check for libraries / set flags using
pkg-config autoconf macros
4 - is a discussion about --as-needed flag from gentoo

[1] http://www.openismus.com/documents/linux/using_libraries/using_libraries.shtml
[2] http://www.openismus.com/documents/linux/automake/automake.shtml
[3] http://library.gnome.org/users/anjuta-build-tutorial/stable/library-autotools.html.en
[4] http://www.gentoo.org/proj/en/qa/asneeded.xml

-- 
With best regards


Dmitrijs Ledkovs (for short Dima),
Ледков Дмитрий Юрьевич



More information about the sword-devel mailing list