Link Errors with Net Functions

Jim Balter jqb@netcom.com
Tue Mar 11 18:40:00 GMT 1997


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@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list