Subject: Re: Link Errors with Net Functions
From: [email-masked] (Jim Balter)

11 Mar 1997 22:46:20 -0800
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
References: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.01Gold (WinNT; I)
Original-To: Michael Godfrey <[email-masked]>
Original-CC: [email-masked]
Original-Sender: [email-masked]

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
"[email-masked]" with one line of text: "help".