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

发布于 2024-08-08 20:59:12 字数 386 浏览 8 评论 0原文

在 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 发行版中?你可能会想象这有相当广泛的需求,但谷歌不会告诉我。

On Solaris, when you compile a program that uses sockets, you need to link it with -lnsl -lsocket. Many such programs were originally written for Linux (where no extra libraries are needed), and therefore do not check for these libraries in their configure scripts, even though that is a rather simple addition. Something like this (untested):

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

Is there a canonical way to do this check? Maybe even included in the autoconf distribution? You would imagine that there is a rather widespread need for that, but Google wouldn't tell me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

总攻大人 2024-08-15 20:59:12

我认为最接近检查这一点的规范方法<来自 Autoconf 存档 的代码>AX_LIB_SOCKET_NSL 宏:

# ===========================================================================
#        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 <[email protected]>
#   Copyright (c) 2008 Stepan Kasal <[email protected]>
#   Copyright (c) 2008 Warren Young <[email protected]>
#
#   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])])
])

i think the closest to a canonical way to check this is the AX_LIB_SOCKET_NSL macro from the Autoconf 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 <[email protected]>
#   Copyright (c) 2008 Stepan Kasal <[email protected]>
#   Copyright (c) 2008 Warren Young <[email protected]>
#
#   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])])
])
熊抱啵儿 2024-08-15 20:59:12

我记不起任何完成的代码,但您通常想检查是否可以先链接一个调用 gethostbyname() 函数的程序,而无需任何额外的库。仅当失败时,您才需要尝试 nsl 库。

类似的事情也适用于例如m 库。

I can't remember any finished code off the top of my head, but you usually want to check whether you can link a program calling the gethostbyname() function without any extra libs first. Only if that fails, you want to try the nsl library.

Similar things apply e.g. for the m library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文