Unresolved External Symbol

TomO picture TomO · Jul 20, 2009 · Viewed 12.5k times · Source

Possible Duplicate:
What is an undefined reference/unresolved external symbol error and how do I fix it?

I am working on wrapping a large number of .h and .lib files from native C++ to Managed C++ for eventual use as a referenced .dll in C#.

I have the .lib files linked in and everything has been going smoothly so far. Upon wrapping the latest .h file, I hit a snag when 2 functions came back with the link error:

error LNK2019: unresolved external symbol __imp__htonl@4 referenced in function
"public: void __thiscall Field::setCharacter(unsigned char,int)"
(?setCharacter@Field@@QAEXEH@Z) myutils.lib 

I have referenced myutils.lib in the linker options, so that shouldn't be the issue.

What's strange is that I have about 20 functions in this particular .h file and all of the rest are linking just fine except for 3 functions.

Any ideas?

Answer

Christopher picture Christopher · Jul 20, 2009

The missing symbol is __imp__htonl@4, which is a C++ mangled name for htonl, which is a function that converts a long value from host to network order. The @4 is used to mangle the input parameters and is part of C++ support for overloaded functions to allow the linker to resolve the right function w/o name collisions.

Make sure that you are linked to the network library that you are referencing this symbol from. Presumably your package is using some special definition of this symbol, instead of the MACRO that it usually is.