LNK2019 / 2001: unresolved external symbol - c++

I've seen similar questions online that are problems with people forgetting to include certain things, etc. However I'm getting this error after checking out our code from subversion--others have done the same without getting this problem. My question: is there anything that could've happened on my machine to cause this linker error, either in Visual Studio settings (but not something that would affect the .sln file) or outside Visual Studio?
Lnk2019, from here states:
unresolved external symbol 'symbol' referenced in function 'function'
Lnk2001, from here states
unresolved external symbol "symbol"
Edit: The LNK2019 errors result from the initial LNK2001 error (on a problem creating a certain dll). If I get that dll from someone else on our team (and adjust the creation date to tomorrow so VS won't delete it) I can edit and debug. Of course I would like to not resort to a workaround...

There's a chance that the library you were linked to was a local copy that no longer exists on your machine. We had this happen when someone imported a library dependency and used an absolute path from their C:\ drive to specify its location.

In addition to Tony's answer, this can also happen if you have an older version of the library higher in your lib search path then where the lib you built was copied to. I'd check all the places listed in:
"Tools->Options->Projects and Solutions->VC++Directories->"Show Directories for: Library Files."

Related

Error LNK2019 when trying to use MRPT libraries as external dependency in VS2019 solution

I am implementing a SLAM-algorithm in Visual Studio 2019 where I want to use the ICP algorithm from the MRPT library for scan-matching.
I installed the MRPT library as 32-bit from source code using CMake. Problem is the error I'm receiving when building the solution (shown below). I assume it is because I have not added Additional Library Directories or Additional Dependencies for the Linker, because I can't find the .lib/.dll files anywhere. I tried installing the 64-bit precompiled binaries for Windows, where I found the .lib-files inside a lib-folder which does not appear when compiling manually with the source code - but can't use the same lib's because I need 32-bit (I tried linking to them, but the same error occurred in addition a bunch of warnings that library is 64-bit and target is 32-bit).
The code is pretty much exactly the same as the first example here, with (I believe) all necessary headers included.
The error produced (I also receive many more of the same error for every class I attempt to use from the library):
particle.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall mrpt::poses::CPose2D::CPose2D(double,double,double)" (__imp_??0CPose2D#poses#mrpt##QAE#NNN#Z) referenced in function (function)
The quick question is: Shouldn't the .lib/.dll files be produced when compiling from source code as well? Or is there something embedded in the library so I don't need them, in which case there must be something else wrong?
The more complicated question is: If the missing .dll/.lib-files is not the problem, what could it be?
Sorry if I am missing any relevant information, this is my first post. Just let me know and I will provide.
Any help is greatly appreciated!

unresolved external symbol _WebPInitUpsamplersSSE2 - why?

I have compiled QT5.6.2 myself with Visual Studio 2015 to compile some other software (Telegram desktop; build instructions are here https://github.com/telegramdesktop/tdesktop/blob/dev/docs/building-msvc.md#setup-gypninja-and-generate-vs-solution ).
Curiously, it seems necessary to state that I know what an unresolved external symbol is - but that I still cannot solve my issue, especially since it lies within a library that is not custom-made by me: QT
Now, when I try to compile Telegram with Visual Studio 2015 which depends on QT5.6.2, I get a weird unresolved symbol:
1>qwebpd.lib(upsampling.obj) : error LNK2019: unresolved external symbol
"_WebPInitUpsamplersSSE2" in Funktion
"_WebPInitUpsamplers".
I could not find anything on this function or in which library it might/should be defined.
It seems that the QT Webkit is built with Chromium and that during QT's compilation I have somehow activated some kind of SSE2 extension which, however, does not seem to be available now in Visual Studio 2015. I have also tried in "Project Settings -> C/C++ -> Code Generation" to explicitly activate SSE2 but without help. I have no clue where this function should actually be defined.
I know in general what an unresolved external symbol is, but I do not know how to resolve this error in my specific case with QT.

meet a link error while building opengl project on win7 with visual studio 2013

The compile all goes well. However, when it goes to the link stage, error comes out:
error LNK2001: unresolved external symbol _ptrc_glClear
There're also many other errors with the same link error, including _ptr_glViewport, _ptr_glDrawArrays......
I'm searched in stackoverflow, and find many questions about the link problem of opengl32.lib. I followed their advice, but still it doesn't work.
I also notice that, the problems occurred in others' question(error LNK2019: unresolved external symbol), appear to be somewhat different: what they failed to link is with the prefix "imp", while mine is "ptr".
I wonder, is the problem of the "_ptrc_xxxxx" thing also comes with the opengl32.lib, or did I miss some other libs to link?
Are you using any kind of OpenGL loader library (GLee, GLEW, glLoadGen)? Prefixed OpenGL symbols are usually imposed on your source code by including such a loaders header (which uses some preprocessor magic to turn all OpenGL symbols in your code into symbols referring to the loader). If then your program fails to link with that very loader you'll get these unresolved symbol linker errors.

LNK2001 Error on basic_istream, basic_ostream

I'm trying to get around these link errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) public void __thiscall std::basic_ostream(char,struc std::char_traits<char>>::_0sfx(void)"
I used Visual Studio C++ 2010, and tried with Visual Studio C++ 6.0, but still the same errors show up.
The object file is found, so I am suspecting that it cannot find the implementation of the std library? I've tried /nodefaultlib option on a few libraries (libc.lib, libcmt.lib, msvcrt.lib, etc) but did not improve the situation at all.
Could someone explain why the error occurs and where I should look ?
Tried the solutions suggested in other similar questions but they either are not applicable or do not resolve the problem.
Thanks
You should remove /nodefaultlib option.
This problem could arise if some of your libraries are linked static while other dynamically.
Basically if you have both codes compiled with the static version of CRT (that's compiler switch /MT and /MTd) and dynamic version of CRT (switch /MD, /MDd).
You can see what your project is using in Project Properies - c++ - Code Generaion - Runtime Library)
Make sure all your libraries are compiled with the same switch as you project.

Best practices for debugging linking errors

When building projects in C++, I've found debugging linking errors to be tricky, especially when picking up other people's code. What strategies do people use for debugging and fixing linking errors?
Not sure what your level of expertise is, but here are the basics.
Below is a linker error from VS 2005 - yes, it's a giant mess if you're not familiar with it.
ByteComparator.obj : error LNK2019: unresolved external symbol "int __cdecl does_not_exist(void)" (?does_not_exist##YAHXZ) referenced in function "void __cdecl TextScan(struct FileTextStats &,char const *,char const *,bool,bool,__int64)" (?TextScan##YAXAAUFileTextStats##PBD1_N2_J#Z)
There are a couple of points to focus on:
"ByteComparator.obj" - Look for a ByteComparator.cpp file, this is the source of the linker problem
"int __cdecl does_not_exist(void)" - This is the symbol it couldn't find, in this case a function named does_not_exist()
At this point, in many cases the fastest way to resolution is to search the code base for this function and find where the implementation is. Once you know where the function is implemented you just have to make sure the two places get linked together.
If you're using VS2005, you would use the "Project Dependencies..." right-click menu. If you're using gcc, you would look in your makefiles for the executable generation step (gcc called with a bunch of .o files) and add the missing .o file.
In a second scenario, you may be missing an "external" dependency, which you don't have code for. The Win32 libraries are often times implemented in static libraries that you have to link to. In this case, go to MSDN or "Microsoft Google" and search for the API. At the bottom of the API description the library name is given. Add this to your project properties "Configuration Properties->Linker->Input->Additional Dependencies" list. For example, the function timeGetTime()'s page on MSDN tells you to use Winmm.lib at the bottom of the page.
One of the common linking errors I've run into is when a function is used differently from how it's defined. If you see such an error you should make sure that every function you use is properly declared in some .h file.
You should also make sure that all the relevant source files are compiled into the same lib file. An error I've run into is when I have two sets of files compiled into two separate libraries, and I cross-call between libraries.
Is there a failure you have in mind?
The C-runtime libraries are often the biggest culprit. Making sure all your projects have the same settings wrt single vs multi-threading and static vs dll.
The MSDN documentation is good for pointing out which lib a particular Win32 API call requires if it comes up as missing.
Other than that it usually comes down to turning on the verbose flag and wading through the output looking for clues.