[Top][All Lists]

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

Re: Failure to use -lnsl on Solaris with AC_CHECK_LIB

From: Stepan Kasal
Subject: Re: Failure to use -lnsl on Solaris with AC_CHECK_LIB
Date: Mon, 5 Sep 2005 17:15:41 +0200
User-agent: Mutt/1.4.1i


On Tue, Aug 30, 2005 at 05:04:08PM -0700, Russ Allbery wrote:
> dnl The rat's nest of networking libraries.  The common cases are not to
> dnl need any extra libraries, or to need -lsocket -lnsl.  We need to avoid
> dnl linking with libnsl unless we need it, though, since on some OSes where
> dnl it isn't necessary it will totally break networking.  Unisys also
> dnl includes gethostbyname in libsocket but needs libnsl for socket().
> AC_SEARCH_LIBS([gethostbyname], [nsl])
> AC_SEARCH_LIBS([socket], [socket], ,
>     [AC_CHECK_LIB([nsl], [socket], LIBS="$LIBS -lsocket -lnsl", , -lsocket)])

though I don't have real experience with handling this problems, I'd like
to point out some inconsistencies:

1) Libraries should be _prepended_ to LIBS, not appended.
So if the macro "AC_SEARCH_LIBS([gethostbyname], [nsl]))" decides that -lnsl
is needed, it executes:
        LIBS="-lnsl $LIBS"
So the last line should contain:
        LIBS="-lsocket -lnsl $LIBS"
The reason is that for stsic libraries, the linker searches them only once,
in the order given on the cmdline.  So the most specific ones have to be
at the beginning.  (See also the Autoconf manual for explanation.)

2) The call of AC_CHECK_LIB on the last line uses this library list:
        -lnsl -lsocket $LIBS
Again, this is because it thinks that libnsl is the "more specific" one,
while libsocket is a lower-layer library needed by libnsl.

I guess there is no need to argue which of the two is "more specific";
I just want to point out that the test and the actual LIBS value should
be consistent.

Relying on your information that "-lsocket -lnsl" is the most common case,
which is also consistent that you first call AC_SEARCH_LIBS for libnsl,
I suggest this code:

AC_SEARCH_LIBS([gethostbyname], [nsl])
AC_SEARCH_LIBS([socket], [socket], [],
    [AC_CHECK_LIB([socket], [socket],
                  [LIBS="-lsocket -lnsl $LIBS"], [], [-lnsl])])

Warren, will you please update the Autoconf Macro Archive?

Have a nice day,
        Stepan Kasal

reply via email to

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