gpt4 book ai didi

c++ - 使用 vector 和查找时 C++ 中 Unresolved external 问题

转载 作者:IT老高 更新时间:2023-10-28 21:53:49 26 4
gpt4 key购买 nike

我已经在一个完全独立的项目中尝试了这段代码,它运行良好(唯一的区别是无法运行的项目被导出为 DLL)。代码如下:

RTATMTHLIB.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;
}

RTATMTHLIB.H

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

错误

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

就是这样。我不知道为什么它在另一个项目而不是这个项目中工作......

最佳答案

我发现另一个论坛帖子,似乎有人报告了与您遇到的完全相同的问题。请检查您是否有

_DEBUG

在您的项目设置(在 C/C++ -- 预处理器下)或代码中的某处(或包含文件)中定义。

看起来 std::vector 认为您正在构建调试版本,而实际上您正在创建发布版本。

我希望这会有所帮助。

关于c++ - 使用 vector 和查找时 C++ 中 Unresolved external 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6003368/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com