1

My code works on my school computer when using Visual Studio, but as soon as I tried on my computer with Visual Studio 2012 too, it compiles but gives me this error when I build my project :

Main.obj : error LNK2019: unresolved external symbol "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>>>,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>>>)" (?getFrequency@@YA?AV?$unordered_map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HU?$hash@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@U?$equal_to@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@std@@@2@@std@@V?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@2@V12@@Z) referenced in function _main C:\Users\name.lastname\Documents\Visual Studio 2012\Projects[Cpp]Mapping\Debug[Cpp]Mapping.exe : fatal error LNK1120: 1 unresolved externals

Since it works on my school computer with the exact same code, Im not giving you the code because it is very heavy. I think it the problem is that the linker cannot see the unordered_map class, I know how to add library to my project but not this specific class. Any ideas?

Comment if you really think that the code is important.

Thanks in advance!

EDIT

Here is my Map_Operations.h file where I declare the getFrequency(); method :

#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_ */

And here is the file Map_Operations.cpp where I implement it:

#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;

}

asked Jan 28, 2014 at 21:25

1 Answer 1

1

The problem is not with unordered_map, the problem is with getFrequency.

You must link with the library providing that function.

answered Jan 28, 2014 at 21:31
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for replying. What do you mean by link with the library providing that function?
Your project (or one of your projects's dependencies) is calling a function named getFrequency, which is implemented by an external library, that's the library you must link with.
Well, I have a file Main.cpp where I include "Map_Operations.h" and I've implemented "Map_Operations.cpp" where there is the function getFrequency(); How do i link that then?
ok, edit your post and add the following information: Declaration and definition of the function getFrequency and, confirm if Map_operations.cpp belong to the project (and is compiled). btw, did you try a quick rebuild?
I found the issue.. But it's really weird and I dont know why.. In my getFrequency, i pass an unordered_map by reference, but when I removed it, it compiled and ran perfectly.. And it's because when i declared it I didnt put the & sign so it was as if it wasnt declared! Thanks anyway :)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.