Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
434 views
in Technique[技术] by (71.8m points)

Unresolved externals in C++ when using vectors and find

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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...