Linker error with vector use & Multi-Threaded DLL config

I'm writing a program that uses a library which requires the runtime library to be set to "Multi-Threaded DLL" (Command line: /MD), so it is. Well, recently, I've only used C in my application, but I wish to start using C++ variable types and methods. I tried to do a simple vector operation and while it compiled fine, it generated a linker error when I tried to build.

I pass the following into a function: vector<int>& Parameters
The line: int parameter2 = Parameters.at(1); generates a linker error:

error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: int const & __thiscall std::_Vector_const_iterator<int,class std::allocator<int> >::operator*(void)const " ( D $_Vector_const_iterator@HV $allocator@H@std@@@std@@QBEABHXZ)

(This is using "Debug" as the active config.)

How can this be resolved Remember, I can't change the runtime library type without losing a major component. It seems strange that it only errors with the command line option /MD.


Answer this question

Linker error with vector use & Multi-Threaded DLL config

  • dogbear

    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.



  • D.D.R.

    Thanks for the suggestions! I switched over to /MDd and I just had to ignore the default library "msvcrt.lib". Now everything links up just fine.

    I'm guessing that using the Multi-Threaded DLL debug option uses the debug runtime library "msvcrtd.dll", which replaces the normal runtime library, so everything should be fine. Thanks again!

  • Linker error with vector use & Multi-Threaded DLL config