错误LNK2001:由于ifstream对象,无法解析外部符号

error LNK2001: unresolved external symbol, due to ifstream object

本文关键字:外部 符号 LNK2001 由于 ifstream 对象 错误      更新时间:2023-10-16

错误LNK2001:未解析的外部符号"__declspec(dllimport)public:静态类std::locale::id std::codecvt::id"(__imp_?id@$codecvt@DDH@std@@2V0locale@2@A)

1> CAssertLog.obj:错误LNK2001:未解析的外部符号"__declspec(dllimport)public:static unsigned int __cdecl std::codecvt::_Getcat(类std::locale::facet const**,类std::locale const*)"(__imp_?_Getcat@$codecvt@DDH@std@@SAIPAPBVfacet@locale@2@PBV42@@Z)

1> CAssertLog.obj:错误LNK2001:未解析的外部符号"__declspec(dllimport)public:int__thiscall std::codecvt::unshift(int&,char*,char*)const"(__imp_?unshift@$codecvt@DDH@std@@QBEHAAHPAD1AAPAD@Z)

1> CAssertLog.obj:错误LNK2001:未解析的外部符号"__declspec(dllimport)public:int__thiscall std::codecvt::out(int&,char const*,char const*&;,char*,char*,char*&;)const"(__imp_?out@$codecvt@DDH@std@@QBEHAAHPBD1AAPBDPAD3AAPAD@Z)

1> CAssertLog.obj:错误LNK2001:未解析的外部符号"__declspec(dllimport)public:int__thiscall std::codecvt::in(int&,char const*,char const*&;,char*,char*,char*&;)const"(__imp_?in@$codecvt@DDH@std@@QBEHAAHPBD1AAPBDPAD3AAPAD@Z)

1> C:\performce\sw\apps\gpu\drivers\common\logassert\Release \logasserte.dll:致命错误LNK1120:5个未解析的外部

问题说明:

现在,当我将源代码行"ifstream-fin;"添加到源文件时,我看到了上面的链接错误。如果我删除此源代码行,则代码成功编译。我已经为ifstream对象添加了支持的头文件和命名空间。不确定,为什么我看到这个链接错误。在SO上搜索了类似的错误,并尝试了他们建议的解决方案,但这些解决方案对我不起作用。知道吗?

样本代码

//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?
}

看起来您没有链接到标准库。由于错误消息显示__declspec,我想带有Visual Studios的Windows环境。默认情况下应该工作:进入项目的属性,然后进入链接器:一般情况下,"忽略导入库"应为"否",并且在Input、Ignore All Default Libraries应为No和Ignore特定的默认库应为空。(这些是默认值。)

否则:这可能是由于您的安装问题,例如,如果不是所有文件都存在。