bug-gnulib
[Top][All Lists]
Advanced

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

Re: module gethostname


From: Bruno Haible
Subject: Re: module gethostname
Date: Wed, 15 Sep 2010 20:10:28 +0200
User-agent: KMail/1.9.9

Sam Steingold wrote:
> The only problem which gethostname module fixes is:
> 
> On mingw, this function has a prototype that differs from that
> specified by POSIX, and it is defined only in the ws2_32 library.
> 
> why does it have such extensive dependencies? (sockets! errno!)

Look at the source code (lib/gethostname.c, lib/w32sock.h, lib/errno.in.h):
  - It needs the 'sockets' module, because on Woe32, socket functions are
    not usable without a prior initialization call.
  - It needs to map Woe32 error values to POSIX error values. EWOULDBLOCK is one
    of them, but mingw does not have EWOULDBLOCK in <errno.h>.

> I am now getting
> 
> undefined reference to 
> `_gethostname_used_without_requesting_gnulib_module_gethostname'

This indicates that you have included gnulib <unistd.h>, are using 
gethostname(),
and have not asked for the gnulib module 'gethostname'.
  - If you want to use a POSIX compliant gethostname() function, you need to
    request the 'gethostname' module.
  - If you want to use Win32 gethostname() - handling errors in the Win32 way,
    and guaranteeing the socket library initialization call yourself - then be
    sure to #include <unistd.h>, then #undef gethostname, and then #include
    <winsock2.h> and <ws2tcpip.h>.

> gcc errors on mingw and I have to figure out which gnulib module did this to 
> me.

This is certainly better than if gnulib would let you call the wrong 
gethostname()
function silently.

Bruno



reply via email to

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