title: Constant pointers in header files
body: <p>I have previously encountered the following problem and have been subconsciously avoiding it ever since but have never fully understood why it is happening. Could someone explain to me what is wrong with the following?</p>
  
  <p>In the header file <code>Library.h</code></p>
  
  <pre><code>#ifndef LIBRARY_H
  #define LIBRARY_H
  
  #include &lt;string&gt;
  
  const char ok = 'K';
  
  const char* problem = "Problem";
  const std::string fine = "Fine";
  
  #endif 
  </code></pre>
  
  <p>In the including main file <code>main.cpp</code></p>
  
  <pre><code>#include "Library.h"
  
  using namespace std;
  
  int main()
  {
      return 0;
  }
  </code></pre>
  
  <p>I get the following error when compiling <code>multiple definition of 'problem'</code> even though there are guard conditions in the header file and only one occurrence of the definition of problem. This seems to apply to any pointer I place in the header file but not to normal constants such as <code>ok</code> or <code>fine</code>.</p>
  
  <p>If I change problem to a non constant: <code>char* problem = "Problem"</code> I get warnings about the deprecated conversion but not multiple definitions and it compiles.</p>
  
  <p>I am using g++ 4.6.3 and Code::Blocks 12.11</p>
  
  <p><strong>Update:</strong>
  Have retested with g++ 4.7.1 (with and without Code::Blocks) and no longer get the issue. Regarding those who suggested the use of <code>extern</code> or <code>static</code> is there any other reason to use those in a case like this (where you only want a simple c-string constant) other than compataibility with older compilers?</p>