C++ 中未解决的外部问题当使用向量并找到

发布于 2024-11-07 06:03:11 字数 1459 浏览 6 评论 0原文

我已经在一个完全独立的项目中尝试过这段代码,它工作得很好(唯一的区别是不工作的项目被导出为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请别遗忘我 2024-11-14 06:03:12

我的案例中的问题是调试配置,将运行时库设置为多线程DLL。修复方法是将其更改为多线程调试 DLL。错误消失了。删除 _DEBUG 宏也是一种解决方法,我想这不是一个好主意,因为您最终会得到链接到非调试标准库的调试构建。

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. 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.

十年九夏 2024-11-14 06:03:12

问题是我在 C/C++-> 预处理器中定义了 _DEBUG。将其更改为 NDEBUG 解决了问题。

The problem was I had _DEBUG defined in C/C++->Preprocessor. Changing it to NDEBUG solved the problem.

眼泪也成诗 2024-11-14 06:03:12

为我工作过:
我的例子中的问题是运行时库设置为多线程 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

内心荒芜 2024-11-14 06:03:11

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

_DEBUG

在项目设置(在 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

_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文