Visual Studio 2022 报错模板:
1>*.obj : error LNK2019: 无法解析的外部符号 “… void __cdecl …” (?..),函数“…”(…?..)中引用了该符号
详细错误如下:
已启动生成…
1>------ 已启动生成: 项目: BIOP, 配置: Debug x64 ------
1>pRein.cpp
1>run_models.obj : error LNK2019: 无法解析的外部符号 "private: void __cdecl bTama::initiate(int,int,int,int)" (?initiate@bTama@@AEAAXHHHH@Z),函数 "public: __cdecl bTama::bTama(void)" (??0bTama@@QEAA@XZ) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl bTama::insert(struct IntervalSub)" (?insert@bTama@@QEAAXUIntervalSub@@@Z),函数 "void __cdecl run_btama_backward1(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_backward1@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: bool __cdecl bTama::deleteSubscription(struct IntervalSub)" (?deleteSubscription@bTama@@QEAA_NUIntervalSub@@@Z),函数 "void __cdecl run_btama_backward1(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_backward1@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl bTama::forward_match_accurate(struct Pub const &,int &,class std::vector<struct IntervalSub,class std::allocator<struct IntervalSub> > const &)" (?forward_match_accurate@bTama@@QEAAXAEBUPub@@AEAHAEBV?$vector@UIntervalSub@@V?$allocator@UIntervalSub@@@std@@@std@@@Z),函数 "void __cdecl run_btama_forward(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_forward@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl bTama::backward1_match_accurate(struct Pub const &,int &,class std::vector<struct IntervalSub,class std::allocator<struct IntervalSub> > const &)" (?backward1_match_accurate@bTama@@QEAAXAEBUPub@@AEAHAEBV?$vector@UIntervalSub@@V?$allocator@UIntervalSub@@@std@@@std@@@Z),函数 "void __cdecl run_btama_backward1(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_backward1@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: void __cdecl bTama::backward2_match_accurate(struct Pub const &,int &,class std::vector<struct IntervalSub,class std::allocator<struct IntervalSub> > const &)" (?backward2_match_accurate@bTama@@QEAAXAEBUPub@@AEAHAEBV?$vector@UIntervalSub@@V?$allocator@UIntervalSub@@@std@@@std@@@Z),函数 "void __cdecl run_btama_backward2(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_backward2@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>run_models.obj : error LNK2019: 无法解析的外部符号 "public: int __cdecl bTama::calMemory(void)" (?calMemory@bTama@@QEAAHXZ),函数 "void __cdecl run_btama_backward1(class intervalGenerator const &,class std::unordered_map<int,bool,struct std::hash<int>,struct std::equal_to<int>,class std::allocator<struct std::pair<int const ,bool> > >)" (?run_btama_backward1@@YAXAEBVintervalGenerator@@V?$unordered_map@H_NU?$hash@H@std@@U?$equal_to@H@2@V?$allocator@U?$pair@$$CBH_N@std@@@2@@std@@@Z) 中引用了该符号
1>D:\codes\BIOP\x64\Debug\BIOP.exe : fatal error LNK1120: 7 个无法解析的外部命令
1>已完成生成项目“BIOP.vcxproj”的操作 - 失败。
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
原因:
在其他电脑或另一个操作系统上加入了新文件,提交到了GitHub,然后回到当前电脑拉取代码后,没有把新建的文件引入 VS 项目
解决:
把新建的文件添加到当前项目,“头/源文件 → \rightarrow →添加 → \rightarrow →现有项” 即可