在Solaris网络库中进行autoconf链接的规范方法是什么?

时间:2009-10-27 11:34:50

标签: solaris autoconf

在Solaris上,编译使用套接字的程序时,需要将其与-lnsl -lsocket链接。许多此类程序最初是为Linux编写的(不需要额外的库),因此不会在其配置脚本中检查这些库,即使这是一个相当简单的添加。像这样(未经测试):

AC_SEARCH_LIBS(gethostbyname, nsl, , AC_MSG_ERROR([gethostbyname not found]))
AC_SEARCH_LIBS(connect, socket, , AC_MSG_ERROR([connect not found]))

有没有规范的方法来进行此项检查?甚至可能包含在autoconf发行版中?您可能会认为存在相当广泛的需求,但谷歌不会告诉我。

2 个答案:

答案 0 :(得分:5)

我认为最接近检查此的规范方法是来自AX_LIB_SOCKET_NSL macroAutoconf Archive

# ===========================================================================
#        http://www.nongnu.org/autoconf-archive/ax_lib_socket_nsl.html
# ===========================================================================
#
# SYNOPSIS
#
#   AX_LIB_SOCKET_NSL
#
# DESCRIPTION
#
#   This macro figures out what libraries are required on this platform to
#   link sockets programs.
#
#   The common cases are not to need any extra libraries, or to need
#   -lsocket and -lnsl. We need to avoid linking with libnsl unless we need
#   it, though, since on some OSes where it isn't necessary it will totally
#   break networking. Unisys also includes gethostbyname() in libsocket but
#   needs libnsl for socket().
#
# LICENSE
#
#   Copyright (c) 2008 Russ Allbery <rra@stanford.edu>
#   Copyright (c) 2008 Stepan Kasal <kasal@ucw.cz>
#   Copyright (c) 2008 Warren Young <warren@etr-usa.com>
#
#   Copying and distribution of this file, with or without modification, are
#   permitted in any medium without royalty provided the copyright notice
#   and this notice are preserved.

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

答案 1 :(得分:0)

我不记得任何完成的代码,但你通常想要检查是否可以首先连接调用gethostbyname()函数的程序而不需要任何额外的库。只有在失败时,您才想尝试nsl库。

类似的事情适用于对于m库。