title: How to declare/use extern map in c++
body: <p>I'm not very used and don't really understand the use of global variables in c++, and cannot manage to solve a problem here, although I'm nearly sure I'm using the declarations the right way.
  I've got an unordered map, which contains params from a file. This is working fine, I've outputted the contents, everything ok.
  But I would like this map to be available everywhere in my program, so that I don't have to pass it as an argument every time, hence the use of global variable.
  I've a little typedef :</p>
  
  <pre><code>typedef tr1::unordered_map&lt;string,float&gt; unmap;
  </code></pre>
  
  <p>then the function to read the parameters:</p>
  
  <pre><code>unmap readParameters(string filename);
  </code></pre>
  
  <p>then the global scope declaration (everything outside the main of course, although in the same file, I still don't have any headers):</p>
  
  <pre><code>extern unmap params;
  </code></pre>
  
  <p>The affectation is made in the main() function:</p>
  
  <pre><code>unmap params=readParameters(inputfile_name);
  </code></pre>
  
  <p>(Note: I tried with and without the "unmap", but same error).
  And I've got a function displayInformation() to display its contents in which I use my map "params":</p>
  
  <pre><code>for (unmap::iterator it=params.begin();it!=params.end();it++){
      cout&lt;&lt;it-&gt;first&lt;&lt;" = "&lt;&lt;it-&gt;second&lt;&lt;endl;
  }
  </code></pre>
  
  <p>But g++ moans then :</p>
  
  <pre><code>    Undefined symbols for architecture x86_64:
    "_params", referenced from:
        _main in loca.o
        displayInformation()     in loca.o
  ld: symbol(s) not found for architecture x86_64
  collect2: ld returned 1 exit status
  make: *** [loca] Error 1
  </code></pre>
  
  <p>So how should I declare/use this to be able to see it from any function?</p>