Quel est le moyen canonique de créer une liaison autoconf dans les bibliothèques de réseau Solaris?

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

  •  06-07-2019
  •  | 
  •  

Question

Sous Solaris, lorsque vous compilez un programme utilisant des sockets, vous devez le lier à -lnsl -lsocket . Beaucoup de ces programmes ont été écrits à l'origine pour Linux (ne nécessitant aucune bibliothèque supplémentaire) et ne vérifient donc pas ces bibliothèques dans leurs scripts de configuration, même s'il s'agit d'un ajout assez simple. Quelque chose comme ça (non testé):

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

Existe-t-il un moyen canonique de procéder à cette vérification? Peut-être même inclus dans la distribution autoconf? Vous imaginez qu’il existe un besoin assez répandu, mais Google ne me le dirait pas.

Était-ce utile?

La solution

Je pense que le moyen le plus proche de une façon canonique de vérifier cela est le AXE_LIB_SOCKET_NSL macro de l'archive 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])])
])

Autres conseils

Je ne me souviens d'aucun code fini, mais vous souhaitez généralement vérifier si vous pouvez lier un programme appelant la fonction gethostbyname () sans bibliothèque supplémentaire au préalable. Si vous échouez, vous voulez essayer la bibliothèque nsl .

Des choses similaires s'appliquent, par exemple. pour la bibliothèque m .

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top