首页 文章

错误LNK2019:unordered_map类的未解析外部符号

提问于
浏览
1

我的代码在使用Visual Studio时可以在我的学校计算机上运行,但是当我在使用Visual Studio 2012的计算机上尝试时,它会编译,但在构建项目时会给我这个错误:

Main.obj:错误LNK2019:未解析的外部符号“class std :: unordered_map,class std :: allocator>,int,struct std :: hash,class std :: allocator >>,struct std :: equal_to,class std: :allocator >>,class std :: allocator,class std :: allocator> const,int >>> __cdecl getFrequency(class std :: vector,class std :: allocator>,class std :: allocator,class std :: allocator >>>,类std :: unordered_map,类std :: allocator>,int,struct std :: hash,class std :: allocator >>,struct std :: equal_to,class std :: allocator >>,class std: :allocator,class std :: allocator> const,int >>>>)“(?getFrequency @@ YA?AV?$ unordered_map @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ @@ 2 STD @@ HU?$散列@ V'$ basic_string的@ DU?$ char_traits @ d @ @@ STD V'$分配器@ d @ @@ 2 STD @@@ 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的@ DU?$ char_traits @ d @ STD @ @V?$ @分配器@ d @@ 2性病@@ V'$异体cator @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @ D @ 2 @@ std @@@ 2 @@ 2 @ V12 @@ Z)在函数_main C:\ Users \中引用name.lastname \ Documents \ Visual Studio 2012 \ Projects [Cpp] Mapping \ Debug [Cpp] Mapping.exe:致命错误LNK1120:1个未解析的外部

因为它在我的学校计算机上使用完全相同的代码,所以我没有给你代码,因为它很重 . 我认为问题是链接器无法看到unordered_map类,我知道如何将库添加到我的项目而不是这个特定的类 . 有任何想法吗?

如果你真的认为代码很重要,请评论 .

提前致谢!

EDIT

这是我的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;

}

1 回答

  • 1

    问题不在于 unordered_map ,问题在于 getFrequency .

    您必须链接提供该功能的库 .

相关问题