java map 无法解析的编译问题_错误LNK2019:unordered_map类的未解析外部符号

我的代码在使用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

#include

#include

std::unordered_map <:string int> getFrequency(std::vector<:string> FILE_CONTENT, std::unordered_map<:string int> MASTER_MAP);

#endif /* MAP_OPERATIONS_H_ */

这是我实现它的文件Map_Operations.cpp:

#include "Map_Operations.h"

#include

#include

#include

using namespace std;

unordered_map getFrequency(vector FILE_CONTENT, unordered_map & MASTER_MAP){

unordered_map 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::size_type j = 0; j != FILE_CONTENT.size(); ++j){

string TEMP = FILE_CONTENT[j];

unordered_map::const_iterator MAP_CURRENT = MAP.find(TEMP); // Create iterator to know if the Key is in the MAP or not

unordered_map::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;

}

错误信息 "error LNK2019: 无法解析外部符号 __imp_clock" 表明在程序中使用了函数 __imp_clock,但编译器和链接器无法找到该函数的定义或实现。这种错误通常是由于缺失符号的定义、编译器搜索路径错误编译器/链接器选项错误引起的。 解决这个错误的方法有以下几种: 1. 确保包含了正确的头文件:检查代码中是否包含了正确的头文件,特别是包含了声明 __imp_clock 的头文件。如果没有包含正确的头文件,编译器将无法找到函数的定义。 2. 检查编译器的搜索路径:编译器需要知道在哪里查找函数的定义。确保编译器的搜索路径设置正确,以便能够找到函数的定义。可以通过设置编译器的选项或环境变量来修改搜索路径。 3. 检查编译器/链接器选项:检查编译器和链接器的选项设置,确保没有设置错误的选项。有时候,错误的选项设置可能导致编译无法找到函数的定义。 下面是一个示例代码,演示了如何使用函数 __imp_clock: ```c++ #include <iostream> #include <ctime> int main() { std::clock_t start = std::clock(); // 执行一些操作 std::clock_t end = std::clock(); double duration = (end - start) / (double) CLOCKS_PER_SEC; std::cout << "程序执行时间:" << duration << " 秒" << std::endl; return 0; } ``` 这段代码使用了函数 std::clock() 来计算程序的执行时间。确保在代码中包含了正确的头文件,并且编译器能够找到函数的定义。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值