title: C++ Linker complains multiple definition of char* but not std::string
body: <p>In a big project, I have a .h file which defines a lot of constants within a namespace. Introducing const char*   constants results in linker errors complaining of multiple definitions.</p>
  
  <p><strong>ex.h</strong></p>
  
  <pre><code>#include &lt;string&gt;
  namespace Dv
  {
      const int MAX = 10;
      const std::string NAME = "bobo";
  
      const char* NAME2 = "fred";  // &lt;-- ERROR: multiple definition of `Dv::NAME2'
  }
  </code></pre>
  
  <p><strong>exA.cpp</strong></p>
  
  <pre><code>#include "ex.h"
  void aFunction() { printf("this is aFunction\n"); }
  </code></pre>
  
  <p><strong>exB.cpp</strong></p>
  
  <pre><code>#include "ex.h"    
  void aFunction(void);
  
  int main(int argc, char **argv)
  {
      aFunction();
      return 0;
  }
  </code></pre>
  
  <p><strong>Compile and Link</strong></p>
  
  <pre><code>g++ -c exA.cpp
  g++ -c exB.cpp
  g++ exA.o exB.o -o ex
  exB.o:(.data+0x0): multiple definition of `Dv::NAME2'
  exA.o:(.data+0x0): first defined here
  collect2: ld returned 1 exit status
  </code></pre>
  
  <p>The linker error happens if NAME2 is included in the .h file.  Why?</p>
  
  <p>If MAX is also a POD (like char[]?), why does the linker not complain of multiple <em>int MAX</em> definitions?  (or multiple <em>std::string NAME</em> definitions for that matter?)</p>
  
  <p>I don't understand what's special about char[] in this situation.</p>
  
  <p>Thanks</p>