Visual Studio error "LNK2019: unresolved external symbol" - visual-c++

I get this error in my program. I don't know what that means. can you help me ?
Error 3 error LNK2019: unresolved external symbol
imp_CrtDbgReportW referenced in function "public: class std::_Vector_const_iterator > > & __thiscall
std::_Vector_const_iterator > >::operator+=(int)"
(??Y?$_Vector_const_iterator#V?$_Vector_val#U?$_Simple_types#PAVCommissionEmployee###std###std###std##QAEAAV01#H#Z) C:\Users\Dell\Documents\Visual
Studio 2012\Projects\Base-Commission Employee\Base-Commission
Employee\main.obj

Take a look here please:
The vector class is going to want to tell you that the at() method
failed in debug mode. Thus the reference to CrtDbgReportW(), the
runtime function that displays diagnostics while debugging. When you
link with /MD, you link with the release version of the run-time
library; the one that doesn't tell you anything and is missing the
CrtDbgReportW() export. Thus the linker error.
You can fix this by removing the _DEBUG define from the preprocessor
definitions. If you don't want to lose that valuable tool, tell us
what goes wrong when you link with /MDd.

If you are building a debug version with a static CRT linking (/MT) then just do this:
#define _ITERATOR_DEBUG_LEVEL 0 before#include<vector> or #include<algorithm> and so on...

Related

IdnToAscii linker error

I am trying to use IdnToAscii in my code.
Accourding to msdn
http://msdn.microsoft.com/en-us/library/windows/desktop/dd318149(v=vs.85).aspx
all I need is kernel32.dll. But I receive linking error when trying to build:
Error 1 error LNK2019: unresolved external symbol __imp__IdnToAscii#20 referenced in function _wmain.
Including normaliz.lib to project solves the issue.
The question is why do I have to include it. Is it a mismatch in msdn documentation or I am missing something.
Thanks
Please check the 'Requirements' paragraph of the MSDN:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd318149%28v=vs.85%29.aspx
There you can see that the IdnToAscii method is in the Normaliz.dll (not kernel32.dll)and to use this method you have to includes Normaliz.lib.

Unresolved external symbol __Atomic_fetch_add_4 referenced from LIBCMTD.lib

I've just installed the VS2012 beta, and upgraded my VS2010 project, it seems to compile as it should, but when linking, I get the following errors:
1>LIBCMTD.lib(excptptr.obj) : error LNK2019: unresolved external
symbol __Atomic_fetch_add_4 referenced in function "unsigned long
__cdecl std::_Inc_atomic_counter_explicit(unsigned long &,enum std::memory_order)"
(?_Inc_atomic_counter_explicit#std##YAKAAKW4memory_order#1##Z)
1>LIBCMTD.lib(excptptr.obj) : error LNK2019: unresolved external
symbol __Atomic_fetch_sub_4 referenced in function "unsigned long
__cdecl std::_Dec_atomic_counter_explicit(unsigned long &,enum std::memory_order)"
(?_Dec_atomic_counter_explicit#std##YAKAAKW4memory_order#1##Z)
Google has no reference to these error messages, which is surprising.
It looks as if __Atomic_fetch_add_4 should be an intrinsic for the fetchadd4 op-code, but it's not (as far as I can tell), the proper intrinsic is _InterlockedIncrement.
I have no idea what could be causing this. Interestingly it comes from excptptr.obj, and I have C++ exceptions disabled in this project. Enabling them made no difference.
Edit:
I notice when googling that this symbol only appears to be referenced by GNU code. Perhaps MS have updated the STL for VS2012 and pulled in some GNU reference code that hasn't been caught yet; needs to be changed to use the MS intrinsic?
I was having a similar problem with a project of mine which was compiled in VS2010 and getting the unresolved external symbol __Atomic_fetch_add_4 error when compiled in VS2012.
I couldn't figure out why it was happening but after a "clean solution" and "rebuild all" the problem went away. I suspect there where old obj files lying around that caused the problem.

error LNK2019: unresolved external symbol referenced in function main

I'm using a library to generate multimodal optimization functions using VS2010. I include the header file of the library and tell VS where the library directory is; however, there is no *.lib file that comes with it, just source files and header files, so I can't point VS to "Additional Library Directories".
If I just include the header file and run my code it works fine. If I call any method from that library I get the LNK2019 error:
error LNK2019: unresolved external symbol "void __cdecl g_initialize(char *)" (?g_initialize##YAXPEAD#Z) referenced in function main".
I looked around and everyone is saying I should link the library, but I don't have a library file to begin with. What should I do??
Regards,
There're 2 ways if you have implementation of those header files.
1) You can add it to you project.
2) To compile library yourself, and you will get *.lib files. After this add it to you project.
Read documentation of this library how to use it.
Also you can check if there's implementation methods/functions which declared in header files.

Compile Win32 application without particular dependencies or size bloat

I am trying to build a small Win32 application using Visual C++ 2008, but I want it to run on any modern Windows machine without having to ship additional libraries and without having to bloat its size linking them statically.
I have read many articles around the internet about this topic, like this one.
I understood that a good idea would be to dynamically link my project to msvcrt.dll which can be found in any modern Windows being a system dll, on the contrary of newer runtimes like msvcr90 which change with each new Visual Studio version.
So in the linker options,
I ignored all default libraries (/NODEFAULTLIB)
I added msvcrt.lib to the additional dependencies
But I get a bunch of "unresolved external symbol" errors when compiling, like these ones:
1>StubLib.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall std::bad_cast::~bad_cast(void)" (??1bad_cast#std##UAE#XZ)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast#std##QAE#PBD#Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "public: __thiscall std::bad_cast::bad_cast(class std::bad_cast const &)" (??0bad_cast#std##QAE#ABV01##Z)
1>StubLib.obj : error LNK2001: unresolved external symbol "long const std::_BADOFF" (?_BADOFF#std##3JB)
I also tried to use some alternative C++ runtime libraries designed to reduce size bloat like Minicrt, WCRT etc. but in any case I get "unresolved external symbol" errors.
Any help is greatly appreciated.
The "bloat" in this case comes from the use of the STL. So unless you want to refactor your code to get rid of the STL references, you may simply be out of luck.
However, I can suggest using the WDK to build the application. With Windows XP the msvcrt.dll was "knighted" to a system DLL (i.e. always on board, no need for redistributables) and to my knowledge it was also included in Windows 2000 SP4+SRP. So if these minimum requirements are okay for you, use the WDK to build your application and all the "bloat" will be in DLLs that should be on any supported system already.

LINK ERROR in VC++

I needed help making sense out of the following LNK error which i am getting.
SwitchFunctions error LNK2019: unresolved external symbol "__declspec(dllimport) ??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z" (__imp_??$?8DU?$char_traits#D#std##V?$allocator#D#1##std##YA_NABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##0#PBD#Z) referenced in function "??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z" (??$find#Viterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##std##PBD#std##YA?AViterator#?$vector#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##V?$allocator#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###2##0#V120#0ABQBD#Z)
Have you checked whether you have included all necessary dlls or lib files in your project settings?
Such an error usually indicate that you have used a function which definition is found, but implementation is not. Usually in the case of external libraries, the implementation is inside a dll or a static lib. Failure to provide the dll or the static lib will cause the linking to fail.
Which version of Visual Studio are you using? This might be relevant for VS2005:
Link error using a CString derived class from a DLL

Resources