3

I have a visual studio 2012 c++ project. I recently uninstalled it and installed visual studio 2015 and upgraded the project. When i am building the project, getting error as shown below:

Error LNK2019 unresolved external symbol _memcmp referenced in function

Moreover i have not used anywhere in my code memcmp fucntion.

I used the linker verbose function and could see below in output file:

Found _memcmp

Referenced in MyC++Project.obj

Referenced in libcpmtd.lib(xstrcoll.obj)

Loaded libvcruntimed.lib(__memcmp_.obj)

Two questions here

1.even though i have not used memcmp in my code why i am getting that linker error?

2.why is memcmp being loaded as __memcmp_.obj

I have the following settings also in my project:

1.C++-->Code generation-->Runtime Library is set to /MTd

2.Linker-->Ignore All default libraries is set to nothing

I have tried all the project settings but everything in vain.

I have issue only with this memcmp function which i have not used.

I have used mamcpy and memset and do not have issue with those

Roop
  • 51
  • 1
  • 5
  • 1
    Possible duplicate of [Why am I not able to build Vim with Visual Studio 2015 RC command line tools?](http://stackoverflow.com/questions/29986585/why-am-i-not-able-to-build-vim-with-visual-studio-2015-rc-command-line-tools) – Humam Helfawi Dec 15 '15 at 09:36
  • i am having issue only with memcmp function which i have not used. I have used memcpy and memset in my code and those do not have any issues. – Roop Dec 15 '15 at 09:41
  • The verbose output says xstrcoll.obj referenecs _memcmp, so there's probably the answer to your first question. – stijn Dec 15 '15 at 09:49
  • what third party libraries are you using? Looks like an extern C / name mangling issue. – Phil Williams Dec 15 '15 at 10:34
  • No use of 3rd party libraries. – Roop Dec 15 '15 at 12:55

3 Answers3

8

Explicitly add vcruntime.lib or other appropriate version of CRT Library to linker parameters (additional dependencies).

When you use memcmp explicitly it is probably handled as intrinsic function and is compiled as inline function.

blaz
  • 314
  • 4
  • 9
  • 2
    Explicitly linking to vcruntime.lib fixed this issue for me. I am porting a C++ application from VS2005 to VS2015 and ran across this error when compiling IDL proxies. The generated code uses IID_GENERIC_CHECK_IID macro which uses memcmp. – Art Dumas Apr 19 '16 at 15:22
  • I added vcruntime.lib, ucrt.lib, made sure I was /MD and changed the call to msvcrtd.lib over to msvcrt.lib for libpng (older version and libz 1.2.5) to build properly from the included project files on windows. – twobob Jul 24 '16 at 01:27
4

Try to add vcruntime.lib and ucrt.lib to your additional dependencies. ===> properties->Linker->Input->Additional Dependencies

Sample path of 'vcruntime.lib': "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\lib\vcruntime.lib"

Sample path of 'ucrt.lib' : "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.16299.0\ucrt\x86\ucrt.lib"

My environment: VS2017 (v141)

Blackcoat77
  • 1,574
  • 1
  • 21
  • 31
0

I've run into this same problem with a legacy Visual C++ 6.0 nmake file with Visual Studio 2015.

This blog article, Introducing the Universal CRT, describes how the Visual Studio 2015 runtime has been split into more than one library. The runtime is now "split the CRT into two logical parts: The VCRuntime, which contained the compiler support functionality required for things like process startup and exception handling, and a “stable” part that contained all of the purely library parts of the CRT" to allow for easier updates.

So long as you do not link with the /nodefaultlib option, all of the correct library files will be found when you link your project. If you link with the /nodefaultlib option, you will need to link several extra libraries when you link. For example, whereas you previously might have just linked msvcrt.lib in order to use the CRT DLL, you will now also need to link vcruntime.lib and ucrt.lib. Here is a table that shows which libraries you will need to link for each “flavor” of the libraries:

Release DLLs   (/MD ): msvcrt.lib   vcruntime.lib      ucrt.lib
Debug DLLs     (/MDd): msvcrtd.lib  vcruntimed.lib     ucrtd.lib
Release Static (/MT ): libcmt.lib   libvcruntime.lib   libucrt.lib
Debug Static   (/MTd): libcmtd.lib  libvcruntimed.lib  libucrtd.lib

See also the Microsoft documentation C runtime (CRT) and C++ Standard Library (STL) .lib files which describes details about the libraries.

See also Microsoft C/C++ change history 2003 - 2015.

Richard Chambers
  • 16,643
  • 4
  • 81
  • 106