1
votes

error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class std::locale::id std::codecvt::id" (__imp_?id@?$codecvt@DDH@std@@2V0locale@2@A)

1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static unsigned int __cdecl std::codecvt::_Getcat(class std::locale::facet const * *,class std::locale const *)" (__imp_?_Getcat@?$codecvt@DDH@std@@SAIPAPBVfacet@locale@2@PBV42@@Z)

1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt::unshift(int &,char *,char *,char * &)const " (__imp_?unshift@?$codecvt@DDH@std@@QBEHAAHPAD1AAPAD@Z)

1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt::out(int &,char const *,char const *,char const * &,char *,char *,char * &)const " (__imp_?out@?$codecvt@DDH@std@@QBEHAAHPBD1AAPBDPAD3AAPAD@Z)

1>CAssertLog.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::codecvt::in(int &,char const *,char const *,char const * &,char *,char *,char * &)const " (__imp_?in@?$codecvt@DDH@std@@QBEHAAHPBD1AAPBDPAD3AAPAD@Z)

1>C:\perforce\sw\apps\gpu\drivers\common\logassert\Release\logassert.dll : fatal error LNK1120: 5 unresolved externals

Issue Explanation:

Now I'm seeing above linking error when I add this source line "ifstream fin;" to source file. If I remove this source line then code successfully compiles. I already added supported header files and and namespace for ifstream object. Not sure, why I'm seeing this linking error. Searched similar error on SO and tried their suggested solutions but those solution didn't work for me. Any idea?

SAMPLE CODE

//In stdafx.h file below code is there 
#pragma once
#include<iostream>
#include<fstream>
using namespace std;

//In program.cpp
#include "stdafx.h"
class A
{
    void B();
    ifstream fin; //now if I make this member static then issue goes away. Can anybody explain?
}
1
You have to give us the source code - at least some reasonable chunk of it to make sense. It could be lots of things e.g. you are linking static but intended to link dynamic libraries, no mentioning of additional libraries or library path in your property sheet in visual studio, etc. I am pretty sure you are using visual studio. - ha9u63ar
What compiler? What does your invocation command look like? - James Kanze

1 Answers

1
votes

It looks like you're not linking against the standard library. Since the error messages show __declspec, I'll suppose a Windows environment, with Visual Studios. By default, this should work: go into the properties of the project, then into Linker: in General, Ignore Import Library should be No, and in Input, Ignore All Default Libraries should be No, and Ignore Specific Default Libraries should be empty. (These are the defaults.)

Otherwise: this could be due to problems with your installation, e.g. if not all of the files are present.