Skip to content
This repository
Browse code

Change use of AC_CHECK_LIB to AC_SEARCH_LIBS.

Patch from Zack Weinberg.  His message:

  This one eliminates all use of AC_CHECK_LIB in the configure script.
  AC_CHECK_LIB has a serious flaw: if the library you mention *exists*
  but is not *necessary* for the function you want, it adds it to
  $(LIBS) anyway.  This was fine in the days of static libraries,
  because the linker would ignore an .a library that didn't contain
  anything you needed. However, ELF shared libraries are different
  (let's not get into why): the linker will by default record a
  DT_NEEDED entry for every shared object mentioned on the link
  command line. Thus, every use of AC_CHECK_LIB is a potential
  unnecessary DT_NEEDED, making extra work for the dynamic loader. The
  cure is simply to use AC_SEARCH_LIBS instead; it first tries to find
  the function you ask for in libc, and only if that doesn't work does
  it try to use the extra library you mention.

  For the same reasons, pkg-config .pc files should distinguish
  between the libraries to use for shared linkage (Libs:) and the
  additional libraries needed for static linkage (Libs.private:). I
  have also made that correction in this patch. I also took the
  opportunity to clean up the substitution variables a little and make
  absolutely sure that the core library does not get linked against
  zlib.

svn:r1338
  • Loading branch information...
commit d3a8ccb8073c3d76b8bfbb4205cfddfd5a351831 1 parent a501d68
Nick Mathewson authored

Showing 3 changed files with 16 additions and 12 deletions. Show diff stats Hide diff stats

  1. +1 0  ChangeLog
  2. +13 11 configure.in
  3. +2 1  libevent.pc.in
1  ChangeLog
@@ -41,6 +41,7 @@ Changes in 2.0.2-alpha:
41 41 o Allow specifying the output filename for rpcgen; based on work by jmansion; patch from Zack Weinberg.
42 42 o Allow C identifiers as struct names; allow multiple comments in .rpc files; from Zack Weinberg
43 43 o Mitigate a race condition when using socket bufferevents in multiple threads.
  44 + o Use AC_SEARCH_LIBS, not AC_CHECK_LIB to avoid needless library use.
44 45
45 46
46 47 Changes in 2.0.1-alpha:
24 configure.in
@@ -45,22 +45,24 @@ dnl AC_DISABLE_SHARED
45 45 AC_SUBST(LIBTOOL_DEPS)
46 46
47 47 dnl Checks for libraries.
48   -AC_CHECK_LIB(socket, socket, [AC_SUBST( [LIBSOCKET], ["-lsocket"] )] )
49   -AC_CHECK_LIB(resolv, inet_aton, [AC_SUBST( [LIBRESOLV], ["-lresolv"] )] )
50   -AC_CHECK_LIB(rt, clock_gettime, [AC_SUBST( [LIBRT], ["-lrt"] )] )
51   -AC_CHECK_LIB(nsl, inet_ntoa, [AC_SUBST( [LIBNSL], ["-lnsl"] )] )
  48 +AC_SEARCH_LIBS([inet_ntoa], [nsl])
  49 +AC_SEARCH_LIBS([socket], [socket])
  50 +AC_SEARCH_LIBS([inet_aton], [resolv])
  51 +AC_SEARCH_LIBS([clock_gettime], [rt])
52 52
53 53 dnl Determine if we have zlib for regression tests
  54 +dnl Don't put this one in LIBS
  55 +save_LIBS="$LIBS"
  56 +LIBS=""
54 57 ZLIB_LIBS=""
55   -ZLIB_CFLAGS=""
56   -AC_CHECK_LIB(z, inflateEnd,
  58 +have_zlib=no
  59 +AC_SEARCH_LIBS([inflateEnd], [z],
57 60 [have_zlib=yes
58   - ZLIB_LIBS="-lz"
59   - AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])],
60   - [have_zlib=no])
  61 + ZLIB_LIBS="$LIBS"
  62 + AC_DEFINE(HAVE_LIBZ, 1, [Define if the system has zlib])])
  63 +LIBS="$save_LIBS"
61 64 AC_SUBST(ZLIB_LIBS)
62   -AC_SUBST(ZLIB_CFLAGS)
63   -AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" != "no"])
  65 +AM_CONDITIONAL(ZLIB_REGRESS, [test "$have_zlib" = "yes"])
64 66
65 67 dnl Checks for header files.
66 68 AC_HEADER_STDC
3  libevent.pc.in
@@ -10,6 +10,7 @@ Description: libevent is an asynchronous notification event loop library
10 10 Version: @VERSION@
11 11 Requires:
12 12 Conflicts:
13   -Libs: -L${libdir} -levent @LIBSOCKET@ @LIBRESOLV@ @LIBRT@ @LIBNSL@ @ZLIB_LIBS@
  13 +Libs: -L${libdir} -levent
  14 +Libs.private: @LIBS@
14 15 Cflags: -I${includedir}
15 16

0 comments on commit d3a8ccb

Please sign in to comment.
Something went wrong with that request. Please try again.