在C ++中使用向量和查找时未解析的外部 [英] Unresolved externals in C++ when using vectors and find
问题描述
我在一个完全独立的项目中尝试过这个代码,它工作正常(唯一的区别是,不工作的项目被导出为DLL)。以下是代码:
RTATMATHLIB.CPP
#includestdafx.h
#includeRTATMATHLIB.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 {
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
$ b
__ declspec(dllexport)double someFunc(double ** Y,int length);
错误
错误1错误LNK2019:未解析的外部符号__imp___CrtDbgReportW在函数public:__thiscall std :: _ Vector_const_iterator< double,class std :: allocator< 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.obj RTATMATHLIB
错误2致命错误LNK1120:1未解析的外部
就是这样。我不知道为什么它在其他项目中工作,而不是这个...
我发现了另一个论坛帖子,有人似乎报告了同样的具体问题,你有。请检查您是否有
_DEBUG
p>看起来std :: vector认为你在构建一个调试版本,当你事实上创建一个发布版本。
我希望这有助于。 p>
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...
解决方案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.
这篇关于在C ++中使用向量和查找时未解析的外部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!