title: How can I do when when get the error: Undefined symbols for architecture x86_64?
body: <h1>Issue</h1>
  <p>I want to overload the operator <code>+=</code> in the class of <code>Complex</code>, but I get this error when I compile this project by <code>g++ main.cpp complex.cpp -I complex.hpp -o out</code>:</p>
  <pre><code>Undefined symbols for architecture x86_64:
    &quot;Complex::operator+=(Complex const&amp;)&quot;, referenced from:
        _main in main-bee8d4.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  <h1>Project</h1>
  <p><strong>project tree</strong></p>
  <pre><code>.
  ├── complex.cpp
  ├── complex.hpp
  └── main.cpp
  </code></pre>
  <p><strong>complex.hpp</strong></p>
  <pre><code>#ifndef __COMPLEX__
  #define __COMPLEX__
  
  class Complex
  {
  public:
      Complex(double x=0, double y=0):re(x), im(y){};
      double real() const {return re;}
      double imag() const {return im;}
      Complex&amp; operator+=(const Complex&amp; res);
  private:
      double re,im;
  };
  #endif
  </code></pre>
  <p><strong>complex.cpp</strong></p>
  <pre><code>#include &quot;complex.hpp&quot;
  
  inline Complex&amp; 
  Complex::operator+=(const Complex&amp; res)
  {
      this-&gt;re += res.re;
      this-&gt;im += res.re;
      return *this;
  };
  </code></pre>
  <p><strong>main.cpp</strong></p>
  <pre><code>#include &quot;complex.hpp&quot;
  #include &lt;iostream&gt;
  
  int main()
  {
      Complex c1(1, 1);
      Complex c2(3, 4);
      c2 += c1;
      std::cout &lt;&lt; &quot;real part：&quot; &lt;&lt; c2.real()  &lt;&lt; &quot;, &quot;
                &lt;&lt; &quot;image part：&quot; &lt;&lt; c2.imag() &lt;&lt; std::endl;
      
      return 0;
  }
  </code></pre>
  <h1>g++</h1>
  <pre><code>$g++ -v
  Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1
  Apple clang version 12.0.0 (clang-1200.0.32.29)
  Target: x86_64-apple-darwin19.6.0
  Thread model: posix
  InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  </code></pre>