Solaris 네트워크 라이브러리에서 AutoConf 링크를 만드는 정식 방법은 무엇입니까?

StackOverflow https://stackoverflow.com/questions/1630225

  •  06-07-2019
  •  | 
  •  

문제

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 분포에도 포함되어 있습니까? 당신은 그에 대한 광범위한 필요가 있다고 생각할 것입니다. 그러나 Google은 나에게 말하지 않을 것입니다.

도움이 되었습니까?

해결책

나는 가장 가까이 있다고 생각합니다 이것을 확인하는 표준 방법 입니다 AX_LIB_SOCKET_NSL 매크로 ~로부터 Autoconf 아카이브:

# ===========================================================================
#        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])])
])

다른 팁

내 머리 꼭대기에서 완성 된 코드를 기억할 수는 없지만 일반적으로 귀하는 일반적으로 귀하가 gethostbyname() 먼저 여분의 libs없이 기능합니다. 그것이 실패한 경우에만 시도하고 싶습니다. nsl 도서관.

비슷한 것들이 예를 들어 적용됩니다 m 도서관.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top