Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: LNK 2019 : unresolved external symbol _imp_CrtDbgReportw in Visual Studio

I have written a program that splits a string when the respective delimiter occurs. But a different error is occurring like :

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

I tested the same program in dev c++ and it is working fine but in visual studio these type of problems are raising.

My Program:

#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;

}

I even tried removing the header and changing the main() function to int main() and int main(void). But the same error occurs in visual studio. Please anyone help me.

like image 258
Hema Chandra Avatar asked Mar 15 '17 04:03

Hema Chandra


People also ask

How do I fix unresolved external symbol?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do I fix lnk2019 linker tools error?

You can fix the errors by including the source code file that contains the definitions as part of the compilation. Alternatively, you can pass . obj files or . lib files that contain the definitions to the linker.

How do I fix lnk2001?

To fix this issue, add the /NOENTRY option to the link command. This error can occur if you use incorrect /SUBSYSTEM or /ENTRY settings in your project. For example, if you write a console application and specify /SUBSYSTEM:WINDOWS, an unresolved external error is generated for WinMain .

What is an unresolved external symbol in C++?

Unresolved external references occur when the symbol for a function or global variable is referenced in a program, but none of the object files or libraries specified in the link step contain a definition for that symbol.


1 Answers

CrtDbgReport is defined in debug version of CRT (C Run-time Library). You are most likely building debug configuration but linking against release version of CRT.

Check Properties -> C/C++ -> Code Generation -> Runtime library.

Other possibility is that you are building release configuration but have some define that is causing string to be built in debug configuration. The easiest example of this would be:

#define _DEBUG
#include <string>

and building your example in release will cause exactly this problem even if the correct runtime library is chosen.

like image 128
mpiatek Avatar answered Oct 19 '22 22:10

mpiatek