Unresolved External Symbol [duplicate] - c++

This question already has answers here:
Closed 10 years ago.
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?

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.

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

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

Related

LNK2019 unresolved external symbol after moving functions to another header file

I had two array templates in one of my header files, everything worked well. Then I thought, I'd better get some more pedantism into my code, so I moved them all into another header file, mostly just for them (and for another function, that wants to use one of them). And then I got LNK2019 error every time I used functions from these templates in other header files.
Since everything was good before I pasted my code elsewhere, I assume the code is okay, it's just my lack of understanding. Basically, the question is: why do I get a linker error when I moved my function to another header file?
Here is an example of one of my errors:
Error LNK2019 unresolved external symbol "public: char __thiscall C2DArray::Get(int,int)" (?Get#?$C2DArray#D##QAEDHH#Z) referenced in function "public: char __thiscall SGame::GetRecordOutput(int,int)" (?GetRecordOutput#SGame##QAEDHH#Z) Mastermind C:\Users\Master\Documents\Visual Studio 2015\Projects\Mastermind\Mastermind\Menu.obj 1
I'm using Visual Studio 2015 if it matters.
Thank you for the reply. As it seems, I have resolved my problem. The cause was the class templats, which were not specialized (and had to be). All I had to do is include what types of these templates I wanted. Sorry for posting before doing more extensive research.

MFC CString Linker error between two projects

I have 2 projects in c++ (MFC)
One is a library project which im using in the second one (an executable one).
They work together great, until I call a function from the regular project that takes a CString as argument. I get a linker error like this
error LNK2019: unresolved external symbol "public: void __thiscall
CTextDisplay::SetText1(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,
class ATL::ChTraitsCRT<wchar_t> > >)" (?SetText1#CTextDisplay##QAEXV?$CStringT#_WV?
$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z) referenced in function
"public: void __thiscall CManualPane::SetBeadCountFor(int,double)"
(?SetBeadCountFor#CManualPane##QAEXHN#Z) C:\source\IQ-Project\IQ\ManualPane.obj IQ
The executable project has its character set to UNICODE but the Library has it set to Multy-Byte chatacter set. I really can't change them without getting ridiculous amounts of errors.
Any suggestions?
Edit: The reason we have different settings in these two projects is because the Executable project is basically an external project that my group didn't build or create. We just had to bring it in and use it. The library project is something we've all been working on for a couple years.
When you include the headers of the library project in the executable, there is likely a typedef which is used in the declaration of the function. Since the executable uses UNICODE, the declaration is now in UNICODE. However, the library implementation is still in MultiByte and so the definition doesn't match the declaration leading to the linker error.
Look into how these typedefs are being setup, and you might be able to do some special #define, #undef around the included header.
In the end it proved to be a better idea to avoid having unicode and multybyte projects in the same solution so I moved it all to unicode and went from there

Confusion about dllexport/dllimprt

I've build an incredibly simple container (barely more than a struct) as a simple test of templates and libraries in c++. It holds an arbitrary type of data and keeps track of it's highest valued member and whether the data has changed since it was last accessed, and is contained in tiny .dll generated by the newest msvc compiler. All I want to do is link this library to another project in Qt Creator, which I've configured to use msvc as it's compiler ( I need to use Qt to interact with .ui files efficiently). I get an unresolved external symbol for each function in the object that is called, e.g. :
LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall collectionContainer<int>::collectionContainer<int>(int *,short,long)" (__imp_??0?$collectionContainer#H##QAE#PAHFJ#Z) referenced in function _main
I'm not sure what to do here, as I was under the impression that that is the exact symbols I should expect to see when exporting a library.
The functions all have CONTAINER_API defined in the usual way that visual studio conditionally imports/exports functions. I'm sure I've just misinterpreted something, but I'm running out of ideas.
I wonder if this error has nothing to do with DLLs and it's just a case of not putting the template implementation in a header file. See here

unresolved external symbol compile error

I frequently have this problem when I try a new library. This time I work with PointGrey Camera and try to use its API libraries (some dll, lib, header files). Mostly, problems were fixed by configuring the SDK (I'm using VS2008) Tools/Options/VC++ Directories/include files(/library files)(/executable files),
I also tried with project configuration:
+ project properties/linker/input/additional dependencies
+ project properties/linker/General/Additional Library Directories
This time, with all this, I still have the error.
Is there a general method to deal with this problem?
do I need to understand this diagnosis from VS2008?
Error 1 error LNK2019: unresolved external symbol __imp__flycaptureGetPacketInfo referenced in function "enum FlyCaptureError __cdecl initializeStandardEventSizes(void *,struct FlyCaptureImageEvent * const)" (?initializeStandardEventSizes##YA?AW4FlyCaptureError##PAXQAUFlyCaptureImageEvent###Z) main_2.obj test
does using analysis tool such as Dependencies Walker ensure to solve these problems well??
This message says that you used a symbol (a function or a variable) in your code. This symbol was probably declared somewhere (most likely in a header file you included in your code) otherwise there would have been a compilation error. When the linker searched for the symbol (in both your object files and the lib files you instructed it to look in) it couldn't find it.
That usually happens because you forgot to let the linker know about a lib you want it to search in.
Most libraries come with a set of instruction that is supposed to help you set up everything correctly and avoid running into these problems.
This problem has been solved lately. I installed the incompatible library of PointGrey. That's why it didn't work. But this says something between "incompatible library" and "unresolved exertal symbol error"

Linking error: LNK2019 & LNK1120

First I had some OpenCL code and when I put it away in another function, I got this error, then I thought maybe its something with OpenCL, but now even my every normal code suddenly appears to report this error whenever I make new function and put main function code in those functions. I have rechecked that prototypes, functions calls and function definitions are exactly same and matches, also since I have this problem with those functions in which there are more arguments like upto 8 or 10 but I read that C/C++ functions supports more 50 or so arguments passing. The error information is:
ImgConv.obj : error LNK2019: unresolved external symbol "void __cdecl function(.............) (?conv_ser##YAXPBMPAM10HHH#Z) referenced in function _main
fatal error LNK1120: unresolved externals
I am reporting error that has lot of forum entries and solution information such as linking some library function or functions prototyping mistakes etc, I have read them but there is non related to my problem.
Check the linker input settings in your project configuration and make sure that the appropriate libraries are included (or add them to the project itself). Visual Studio doesn't do this automatically just because you add the source code to your project.
If 'conv_ser' is a function that you created make sure that the implementation for that function is available in the project. Double check to make sure that the arguments in the prototype (typically in the header) match that of the any implementation you have added.
Have you tried deleting all instances of void __cdecl function? Just search through your project and comment it out. See if your code will compile after this.