title: C++ linker command failed with exit code 1
body: <p>Source of <code>MaxSumOfSubArray.cpp</code>:</p>
  
  <pre><code>#include &lt;iostream&gt;
  namespace MaxSumOfSubArray {
  
      void run() {
          std::cout &lt;&lt; "hey hey";
      }
  
  }
  </code></pre>
  
  <p>Source of <code>main.cpp</code>:</p>
  
  <pre><code>#include "MaxSumOfSubArray.cpp"
  
  int main(int argc, const char * argv[])
  {
      MaxSumOfSubArray::run();
      return 0;
  }
  </code></pre>
  
  <p>But I get the error:</p>
  
  <pre><code>duplicate symbol __ZN16MaxSumOfSubArray3runEv in:
  /Users/li.tonghui/Library/Developer/Xcode/DerivedData/CppChallenges-eobfuxlkqjfgebendxkoqbsvsbmr/Build/Intermediates/CppChallenges.build/Debug/CppChallenges.build/Objects-normal/x86_64/main.o
  /Users/li.tonghui/Library/Developer/Xcode/DerivedData/CppChallenges-eobfuxlkqjfgebendxkoqbsvsbmr/Build/Intermediates/CppChallenges.build/Debug/CppChallenges.build/Objects-normal/x86_64/MaxSumOfSubArray.o
  ld: 1 duplicate symbol for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>Why am I getting this error and how to solve it?</p>