This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Link Errors with Net Functions

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 *)':
>      .../ 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
"" with one line of text: "help".

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]