title: Undefined reference to global unordered_map
body: <p>I have three files:</p>
  
  <pre><code>TableGenerataor.h
  TableGenerataor.cpp
  Analyzer.cpp
  </code></pre>
  
  <p>I have declared unordered_map in TableGenerator.h and using that I create the object of unorderd_map in TableGenerataor.cpp.</p>
  
  <pre><code>map_t obj1;
  data d;
  </code></pre>
  
  <p>TableGenerator.h</p>
  
  <pre><code>namespace N {
  
  typedef std::tuple&lt;int, char&gt; key_t;
  
  struct key_hash : public std::unary_function&lt;key_t, std::size_t&gt;
  {
  std::size_t operator()(const key_t&amp; k) const
  {
  return std::get&lt;0&gt;(k) ^ std::get&lt;1&gt;(k) ;
  }
  };
  
  struct key_equal : public std::binary_function&lt;key_t, key_t, bool&gt;
  {
  bool operator()(const key_t&amp; v0, const key_t&amp; v1) const
  {
  return (
  std::get&lt;0&gt;(v0) == std::get&lt;0&gt;(v1) &amp;&amp;
  std::get&lt;1&gt;(v0) == std::get&lt;1&gt;(v1) 
  );
  }
  };
  
  struct data
  {
  int AlertNo;
  
  };
  
  typedef std::unordered_map&lt;const key_t,data,key_hash,key_equal&gt; map_t;
  
  }
  
  enter code here
  </code></pre>
  
  <p>I want to use this unordered_map created in TableGenerator.cpp file in  Analyzer.cpp. I want to keep this unordered_map till the end of the program. For that purpose I want to make unordered_map global. Global seems to be better option rather than sending map as parameter to other function. I use the keyword extern in Analyzer.cpp.</p>
  
  <p>extern map_t obj1;
  extern data d;</p>
  
  <p>but it still says that <strong>undefined reference to obj1</strong> when compiling. Please help me how do I make unorderd_map Global to make use of it in other cpp files. Secondly, is their any other better way to do this thing rather than making map global.    </p>