19

I have tried this code in a totally separate project, and it works fine (the only difference being that the project that is not working is being exported as a DLL). Here is the code:

RTATMATHLIB.CPP

#include "stdafx.h"
#include "RTATMATHLIB.h"
#include <math.h>
#include <vector>
#include <algorithm>
#include <stdexcept>

using namespace std;

double someFunc(double** Y, int length)
{
    vector<double> myVector;

    for(int i = 0; i < length; i++)
    {
        double value = (*Y)[i];

        vector<double>::iterator it = find(myVector.begin(), myVector.end(), value);

        if(it != myVector.end())
        {
            continue;
        }
        else
        {
            myVector.push_back(value);
        }
    }
    return 0;
}

RTATMATHLIB.H

__declspec(dllexport) double someFunc(double** Y, int length);

ERRORS

Error   1   error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<double,class std::allocator<double> >::_Vector_const_iterator<double,class std::allocator<double> >(double *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@NV?$allocator@N@std@@@std@@QAE@PANPBV_Container_base_secure@1@@Z)  RTATMATHLIB.obj RTATMATHLIB
Error   2   fatal error LNK1120: 1 unresolved externals

And that's it. I am not sure why it works in the other project and not this one...

LunchMarble
  • 5,079
  • 9
  • 64
  • 94
  • I'm guessing there is a debug runtime problem. What are your project settings? Any warnings? – Bart May 14 '11 at 17:08
  • 1
    @Bart: I am fairly new to C++ and so I am not sure which settings you mean? I apologize in advance for my ignorance. But there are no warnings. – LunchMarble May 14 '11 at 17:17
  • make sure at the top that the little dropdown list says "Release" not "Debug". Also if you're just making C++ programs, when you create a New Project make sure you select the bubble that says "Empty Project" in the options (I see stdafx.h in your headers list, which is usually used in Windows applications). – Seth Carnegie May 14 '11 at 17:50

4 Answers4

36

I found another forum post, where somebody seems to have reported the same exact problem that you are having. Please check to see if you have

_DEBUG

defined either in your project settings (under C/C++ -- Preprocessor) or somewhere in your code (or include files).

It looks as if std::vector thinks you are building a debug build, when you are in fact creating a release build.

I hope this helps.

Lucky Luke
  • 1,373
  • 2
  • 13
  • 18
28

The problem in my case was a Debug configuration with Runtime Library set to Multi-threaded DLL. The fix was to change it to Multi-threaded Debug DLL. The error is gone. Removing _DEBUG macro was also a kind of workaround, by I guess it's not a good idea because you end up with debug build linked to non-debug standard library.

cubuspl42
  • 7,833
  • 4
  • 41
  • 65
  • 1
    This fixed the problem for me. I was getting: "error LNK2001: unresolved external symbol __imp__CrtDbgReportW". It had to do with my switch from 32 bit to 64 bit in my Direct3D11 application. In Visual Studio 2013 Community, this setting is found under Project Properties -> Configuration Properties -> C/C++ -> Code Generation -> Runtime Library. – Andrew May 19 '15 at 19:13
  • Me too, I was compiling breakpad with msvc2015 and needed /MD and it worked for release but needed /MDd for debug – edin-m Oct 08 '16 at 20:14
3

The problem was I had _DEBUG defined in C/C++->Preprocessor. Changing it to NDEBUG solved the problem.

Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147
Yonatan Simson
  • 2,395
  • 1
  • 24
  • 35
2

Worked for me with : The problem in my case was a Debug configuration with Runtime Library set to Multi-threaded DLL. The fix was to change it to Multi-threaded Debug DLL

Anurag Daware
  • 441
  • 1
  • 5
  • 15