Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved External Symbol [duplicate]

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?

like image 599
TomO Avatar asked Jul 20 '09 14:07

TomO


3 Answers

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.

like image 187
Christopher Avatar answered Oct 25 '22 06:10

Christopher


Are you sure the signatures match? Be sure to checked for signed-ness and const-ness. Also, make sure functions aren't inlined.

like image 33
eduffy Avatar answered Oct 25 '22 08:10

eduffy


I ran into this error when I compiled against a library and then changed the library before linking. Make sure your headers are the same ones provided by your library (not copied from another architecture, etc). Of course, make sure you're linking against ws2_32.lib (-lws2_32 for mingw/gcc).

Additionally, if you are using GCC/mingw you may want to take a look at this: MinGW linker error: winsock

like image 45
wickedchicken Avatar answered Oct 25 '22 07:10

wickedchicken