cURL / Mailing Lists / curl-library / Single Mail


Suggestion to ignore unused libs

From: Daniel Johnson <>
Date: Fri, 13 Feb 2009 10:12:32 -0500

Libtool has an annoying habit of linking in indirectly linked
libraries on some systems even when those libraries aren't being used.
For example, on Mac OS X when I build libcurl with libidn, I also have
to link in libintl, and therefore anything linking to libcurl also has
to link to libintl. OS X doesn't actually require this for shared
libraries, only static ones, but libtool plays it safe and does it
anyway even if static libraries are disabled, which I usually do.

Some linkers have a switch to automatically remove unused libs at link
time. Gnu ld uses --as-needed, OS X uses -dead_strip_dylibs, and
Solaris uses -z ignore. Those are the ones I know of. I've been adding
-Wl,-dead_strip_dylibs to my OS X builds for a while now with no ill
effects. But I was thinking that it might be good to have configure
check for these flags and add them to LDFLAGS as appropriate. Gnulib
actually has such a macro, gl_IGNORE_UNUSED_LIBRARIES, which I
modified to check for -dead_strip_dylibs and am including below. The
macro should be called before checking for c-ares since the
AC_LINK_IFELSE will always fail if building the included ares because
libcares doesn't exist yet.


This is lib-ignore.m4:
# If possible, ignore libraries that are not depended on.

dnl Copyright (C) 2006 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.

dnl Written by Paul Eggert.
dnl Darwin support added by Daniel Johnson

   AC_CACHE_CHECK([for flag to ignore unused libraries],
      # Link with -lm to detect binutils 2.16 bug with --as-needed; see
      # <
      LIBS="$LIBS -lm"
      # Use long option sequences like '-z ignore' to test for the
      # to forestall problems with linkers that have -z, -i, -g, -n,
etc. flags.
      # GCC + binutils likes '-Wl,--as-needed'.
      # GCC + Darwin ld likes '-Wl,-dead_strip_dylibs'.
      # GCC + Solaris ld likes '-Wl,-z,ignore'.
      # Sun C likes '-z ignore'.
      # Don't try bare '--as-needed'; nothing likes it and the HP-UX
      # native cc issues annoying warnings and then ignores it,
      # which would cause us to incorrectly conclude that it worked.
      for gl_flags in \
        '-Wl,--as-needed' \
        '-Wl,-dead_strip_dylibs' \
        '-Wl,-z,ignore' \
        '-z ignore'
        LDFLAGS="$gl_flags $LDFLAGS"
        test "$gl_cv_ignore_unused_libraries" != none && break

   test "$gl_cv_ignore_unused_libraries" != none &&
     LDFLAGS="$LDFLAGS $gl_cv_ignore_unused_libraries"
Received on 2009-02-13