1

I'm in the process of converting a native C++ Visual Studio 2010 project to Visual Studio 2015 and after fixing a bunch of other stuff I'm finally at the linking stage which is failing with the following error

ucrtd.lib(ucrtbased.dll) : error LNK2005: __crt_debugger_hook already defined in msvcrtd.lib(utility_desktop.obj)

Thinking it may be a C-runtime library mismatch I went back and recompiled all our dependencies using VS2015 and the /MDd switch to control which run-time is used. That didn't fix anything.

According to dumpbin the symbol __crt_debugger_hook is in both libraries, but it only appears in a symbol table in msvcrtd.lib.

There are other executables in my solution that link with ucrtd.lib and msvcrtd.lib yet don't suffer from this problem. The executable that does experience the link failure also links with MFC and BCG, but I don't see how that could be the cause.

Does anyone have any other ideas for what could be causing this problem?

Brett Hall
  • 913
  • 7
  • 12
  • May be answered [here](http://stackoverflow.com/q/2728649/1460794)? – wally Mar 01 '16 at 22:26
  • Nope, that's not the problem. I saw that question when I first started googling around. It's why I went back and recompiled all my dependencies so that I was sure that they we're all using /MDd. The error message I show above is the only error that I'm getting, and the linker output does not show the linker looking in LIBCMT.lib for stuff. – Brett Hall Mar 01 '16 at 22:30

2 Answers2

7

It turns out that the bug isn't in Microsoft's library. Instead it's in the Crypto++ (https://www.cryptopp.com/) library. They forward declare _crt_debugger_hook in a way that is incompatible with changes that were made by Microsoft when they split the c-runtime into ucrtd.lib and msvrtd.lib. The offending line is fipstest.cpp at line 21:

extern "C" {_CRTIMP void __cdecl _CRT_DEBUGGER_HOOK(int);}

the _CRTIMP needs to be removed so that you have

extern "C" {void __cdecl _CRT_DEBUGGER_HOOK(int); }

I've opened a pull request with the Crypto++ folks to fix this (https://github.com/weidai11/cryptopp/pull/151).

Brett Hall
  • 913
  • 7
  • 12
0

After spending some time going back and forth with MS technical support it sounds like this is a bug in VS2015. They couldn't give me any information on when a fix will be available but I can say that it isn't fixed by either update 1 or 2 for VS2015.

Brett Hall
  • 913
  • 7
  • 12
  • Would be nice if you could provide details as to what's the bug, when it hits, etc. any Connect link? – Martin Ba Mar 22 '16 at 21:06
  • I don't have any details at this point. I suspect that the problem is that the symbol is defined in both libraries and we just happened to to hit the magic combination of C-runtime library calls to trigger it to be included leading to the "multiple defined symbols" error. I'll post more details when I have some, for now all I know is that the problem has been "forwarded to the product team". – Brett Hall Mar 24 '16 at 04:37
  • Cheers. (It's just that *I'm* pulling my hair every odd month for a couple of hours with weird linker errors where I can't tell right from left, getting it to run eventually. Most often it's some bad flags combination and/or picking up a `.lib` with the wrong bitness/VS version etc.) Would be interesting to see an actual and explained bug for once. ;-) – Martin Ba Mar 24 '16 at 09:15
  • Turns out the bug isn't microsoft's, see my next answer. – Brett Hall Mar 29 '16 at 17:17