错误LNK2001:由于ifstream对象,无法解析外部符号
error LNK2001: unresolved external symbol, due to ifstream object
错误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特定的默认库应为空。(这些是默认值。)
否则:这可能是由于您的安装问题,例如,如果不是所有文件都存在。
- C++:Application.cpp中抛出了未解析的外部符号(解决方案在问题的末尾,供未来的读者参考)
- 未解析的外部符号_MsiLocateComponentW@12.
- 在C++中使用 gRPC 时未解析的外部符号
- LibPrivoxy: 未解析的外部符号 __declspec(dllimport) int __stdcall Sta
- 尝试从 XamlApplication 编译 C++/WinRT 空白应用程序时,我收到未解析的外部符号 winrt_make_*
- 我收到错误LNK2001:未解析的外部符号(C++代码)
- 可视抽象类 c++(错误 LNK 2001:未解析的外部符号)
- 如何摆脱C++中未解析的外部符号"private: static char"错误?
- 当 lib 已添加到其他依赖项时,如何在 VS 中调试未解析的外部符号错误
- 仅在少数方法(静态或共享库)中解析的外部符号
- 未解析的外部符号"__declspec(dllimport)与 Spdlog c++ 库
- 函数 _main (OPENGL C++) 中引用的未解析的外部符号 ________
- 错误LNK2019未解析的外部符号"public: __thiscall SLinkList<char>::SLinkList<char>(void)"
- 使用静态 constexpr 成员的未解析外部符号
- 引入参数化构造函数后显示 LNK 2019 未解析外部符号的代码错误
- Dlib LNK2001未解析的外部符号USER_ERROR__consistent_build_configurati
- 矛盾的未解决的外部符号+未使用的库与VS2017和FFMPEG 4
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 类模板上一个特定函数的未解析外部符号
- LNK2001:未解析的外部符号public:static类std::vector