delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1997/03/11/22:46:20

From: jqb AT netcom DOT com (Jim Balter)
Subject: Re: Link Errors with Net Functions
11 Mar 1997 22:46:20 -0800 :
Approved: cygnus DOT gnu-win32 AT cygnus DOT com
Distribution: cygnus
Message-ID: <332616A9.EB.cygnus.gnu-win32@netcom.com>
References: <199703112246 DOT OAA25304 AT io DOT nosc DOT mil>
Mime-Version: 1.0
X-Mailer: Mozilla 3.01Gold (WinNT; I)
Original-To: Michael Godfrey <godfrey AT io DOT nosc DOT mil>
Original-CC: gnu-win32 AT cygnus DOT com
Original-Sender: owner-gnu-win32 AT cygnus DOT com

Michael Godfrey wrote:
> 
> I'm having trouble linking with the htons(), htonl(), ntohs(), and
> ntohl() host to/from network byte order functions.
> 
> The compile is clean, and although these functions reside in cygwin.dll,
> I still get the following type of error message at link time:
> 
>      ...libwhatever.a(NetInt.o): In function `NetInt::write(char *)':
>      .../NetInt.cc:20: undefined reference to `htonl(unsigned long)'
> 
> Anyone encountered this before?  Any help will be greatly appreciated.
> Thanks.

When you see a prototype in an "undefined reference" message,
the linker is looking for a C++ (mangled) name.  But htonl is a
C function.  So, you are missing an extern "C" prototype for htonl
prior to your use of it in C++ code.  This means either that you
are missing an #include or are using the wrong #include or that the
#include files are not entirely correct (now, what chance is there
of that among the morass of {my,cygwin32}winsock and inet etc.
header files).  If you are calling htonl from your own code,
you can add
extern "C" unsigned long htonl(unsigned long);

and this might allow you to move on the next bug.

--
<J Q B>
-
For help on using this list, send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019