C++ 中未解决的外部问题当使用向量并找到
我已经在一个完全独立的项目中尝试过这段代码,它工作得很好(唯一的区别是不工作的项目被导出为 DLL)。这是代码:
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
就是这样。我不确定为什么它在另一个项目中有效,而在这个项目中不起作用......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的案例中的问题是调试配置,将
运行时库
设置为多线程DLL
。修复方法是将其更改为多线程调试 DLL
。错误消失了。删除_DEBUG
宏也是一种解决方法,我想这不是一个好主意,因为您最终会得到链接到非调试标准库的调试构建。The problem in my case was a Debug configuration with
Runtime Library
set toMulti-threaded DLL
. The fix was to change it toMulti-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.问题是我在 C/C++-> 预处理器中定义了 _DEBUG。将其更改为 NDEBUG 解决了问题。
The problem was I had _DEBUG defined in C/C++->Preprocessor. Changing it to NDEBUG solved the problem.
为我工作过:
我的例子中的问题是运行时库设置为多线程 DLL 的调试配置。修复方法是将其更改为多线程调试 DLL
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
我发现了另一个论坛帖子,其中似乎有人报告了与您遇到的完全相同的问题。请检查您是否
在项目设置(在 C/C++ - 预处理器下)或代码中的某个位置(或包含文件)中进行了定义。
看起来 std::vector 认为您正在构建调试版本,而实际上您正在创建发布版本。
我希望这有帮助。
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
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.