我的代码在使用Visual Studio时适用于我的学校计算机,但只要我在我的计算机上使用Visual Studio 2012进行了尝试,它也会编译但在构建我时发生此错误项目:错误LNK2019:无法解析的外部符号unordered_map
Main.obj:错误LNK2019:无法解析的外部符号“类的std :: unordered_map,一流的std ::分配器>,INT,结构的std ::哈希类的std ::分配器>>,结构STD :: std :: allocator std :: allocator std :: allocator std :: allocator std :: allocator std :: allocator std :: allocator std :: allocator std :: allocator const std ::分配器,class std :: allocator>>,类std :: unordered_map,类std :: allocator>,int,struct std :: hash,类std :: allocator>>,struct std :: equal_to,cla ss std :: allocator>>,class std :: allocator,class std :: allocator> const,int>>>)“(?getFrequency @@ YA?AV?$ unordered_map @ V?$ basic_string @ DU?$ char_traits @ d @性病@@ V'$ @分配器@ d @@ 2性病@@胡?$ @哈希V'$ @的basic_string杜?$ @ char_traits @ d @@性病V'$ @分配器@ d @@ 2 @性病@@ @ 2 U&$ equal_to @ V'$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@@ 2 @ V'$分配器@ U&$对@ $$ CBV?$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@ H + STD @@@ 2 @@ STD @@ V'$ @矢量V'$ basic_string的@杜?$ @ char_traits @ d @@性病V'$ @分配器@ d @@ 2性病@@ V'$ @分配器V'$ @的basic_string杜?$ @ char_traits @ d @@性病V'$ @分配器D @ 2 @@ std @@@ 2 @@ 2 @ V12 @@ Z)在函数_main中引用 C:\ Users \ name.lastname \ Documents \ Visual Studio 2012 \ Projects [Cpp] Mapping \ Debug [Cpp]映射.exe:致命错误LNK1120:1个未解析的外部设备
由于它的工作原理我的学校计算机具有完全相同的代码,我没有给你代码,因为它非常重。我认为问题是链接器看不到unordered_map类,我知道如何将库添加到我的项目中,但不是这个特定的类。 任何想法?
评论如果你真的认为代码很重要。
在此先感谢!
编辑
这里是我的Map_Operations.h文件,其中我宣布getFrequency();方法:
#ifndef MAP_OPERATIONS_H_
#define MAP_OPERATIONS_H_
#include <string>
#include <unordered_map>
#include <vector>
std::unordered_map <std::string, int> getFrequency(std::vector<std::string> FILE_CONTENT, std::unordered_map<std::string, int> MASTER_MAP);
#endif /* MAP_OPERATIONS_H_ */
这里是文件Map_Operations.cpp,我实现它:
#include "Map_Operations.h"
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
unordered_map <string, int> getFrequency(vector<string> FILE_CONTENT, unordered_map<string, int> & MASTER_MAP){
unordered_map <string, int> MAP;
// Iterate through the current file being copied and push_back all the words in the
// DOCUMENTS_ALL vector and in the MAP to compute their frequency
for(vector<string>::size_type j = 0; j != FILE_CONTENT.size(); ++j){
string TEMP = FILE_CONTENT[j];
unordered_map<string, int>::const_iterator MAP_CURRENT = MAP.find(TEMP); // Create iterator to know if the Key is in the MAP or not
unordered_map<string, int>::const_iterator MAP_MASTER = MASTER_MAP.find(TEMP); // Create iterator to know if the Key is in the MAP or not
if (MAP_CURRENT == MAP.end()){ // If not in the MAP add it without incrementing
MAP[TEMP] = 1;
}else{ // If it is in the MAP then increment and add it
MAP[TEMP] = MAP[TEMP]+1;
}
if(MAP_MASTER == MASTER_MAP.end()){ // If not in the MASTER_MAP then add it
MASTER_MAP[TEMP] = 1;
}else { // If already in it then increment counter
MASTER_MAP[TEMP] = MASTER_MAP[TEMP]+1;
}
}
return MAP;
}
感谢您的回复。与提供该功能的库链接是什么意思? – nichus
您的项目(或您项目的某个依赖项)正在调用名为'getFrequency'的函数,该函数由外部库实现,这是您必须链接的库。 –
那么,我有一个文件Main.cpp,其中包含“Map_Operations.h”,并且我已经实现了“Map_Operations.cpp”,其中有函数getFrequency(); 那么我该如何链接呢? – nichus