使用向量和查找时,C++中未解析的外部

Min*_*wth 19 c++ find unresolved-external stdvector

我在一个完全独立的项目中尝试了这个代码,它工作正常(唯一的区别是不工作的项目被导出为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;
}
Run Code Online (Sandbox Code Playgroud)

RTATMATHLIB.H

__declspec(dllexport) double someFunc(double** Y, int length);
Run Code Online (Sandbox Code Playgroud)

错误

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
Run Code Online (Sandbox Code Playgroud)

就是这样.我不确定为什么它在其他项目中起作用而不是这个...

Luc*_*uke 35

我发现了另一个论坛帖子,有人似乎报告了你遇到的同样问题.请检查一下你是否有

_DEBUG
Run Code Online (Sandbox Code Playgroud)

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

当你实际创建一个发布版本时,看起来好像std :: vector认为你正在构建一个调试版本.

我希望这有帮助.


cub*_*l42 28

我的问题是调试配置Runtime Library设置为Multi-threaded DLL.解决方法是将其更改为Multi-threaded Debug DLL.错误消失了.删除_DEBUG宏也是一种解决方法,我想这不是一个好主意,因为你最终调试构建链接到非调试标准库.