【问题标题】:ERROR: LNK 2019 : unresolved external symbol _imp_CrtDbgReportw in Visual Studio错误:LNK 2019:Visual Studio 中未解析的外部符号 _imp_CrtDbgReportw
【发布时间】:2017-03-15 04:45:55
【问题描述】:

我编写了一个程序,可以在出现相应的分隔符时拆分字符串。但是发生了一个不同的错误,例如:

Error 1   error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: char const & __thiscall std::_String_const_iterator<class std::_String_val<struct std::_Simple_types<char> > >::operator*(void)const " (??D?$_String_const_iterator@V?$_String_val@U?$_Simple_types@D@std@@@std@@@std@@QBEABDXZ)    Source.cpp Using Object_Type Input

我在 dev c++ 中测试了相同的程序,它运行良好,但在 Visual Studio 中,这些类型的问题正在引发。

我的计划:

#include <string>
#include <iostream>
#include<tchar.h>
using namespace std;

 #pragma comment (lib, "ws2_32.lib")

int _tmain(int argc, _TCHAR* argv[])
{

string s = "Enter a line of text,\n next line\n as the\n delimiter: ";
string delimiter = "\n";
size_t pos = 0;
string token;

while ((pos = s.find(delimiter)) != std::string::npos) {
    token = s.substr(0, pos);
    std::cout << token << std::endl;
    s.erase(0, pos + delimiter.length());
}
std::cout << s << std::endl;

return 0;

}

我什至尝试删除标题 并将 main() 函数更改为 int main() 和 int main(void)。但同样的错误发生在视觉工作室。请任何人帮助我。

【问题讨论】:

    标签: c++ c++11 visual-studio-2012


    【解决方案1】:

    CrtDbgReport 在CRT (C Run-time Library) 的调试版本中定义。您很可能正在构建调试配置,但链接到 CRT 的发布版本。

    检查属性 -> C/C++ -> 代码生成 -> 运行时库。

    另一种可能是您正在构建发布配置,但有一些定义导致 string 在调试配置中构建。最简单的例子是:

    #define _DEBUG
    #include <string>
    

    即使选择了正确的运行时库,在发布中构建您的示例也会导致此问题。

    【讨论】:

    • 谢谢。我将运行时库更改为 MTd。它奏效了。
    • 将我的运行时库更改为 MTd 也对我有用。谢谢你们俩。
    猜你喜欢
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 2018-11-19
    • 2023-03-28
    • 2011-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多