1
votes

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;

}

1

1 Answers

1
votes

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

You must link with the library providing that function.