使用向量和查找时 C++ 中未解决的外部问题

Unresolved externals in C++ when using vectors and find(使用向量和查找时 C++ 中未解决的外部问题)
本文介绍了使用向量和查找时 C++ 中未解决的外部问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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@@QAE@PANPBV_Container_base_secure@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

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

defined either in your project settings (under C/C++ -- Preprocessor) or somewhere in your code (or include files).

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

It looks as if std::vector thinks you are building a debug build, when you are in fact creating a release build.

我希望这会有所帮助.

这篇关于使用向量和查找时 C++ 中未解决的外部问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)