title: C++ Undefined Symbol - Simple program that is erroring with external function declaration
body: <p>I'm new to C++, and just learning by doing something that is keeping me interested. But I've come across this really weird issue that I can't resolve for the life of me.</p>
  <p>I've written a few classes, and everything is working fine, but when I build out some functions into the <code>.cpp</code> file (external declaration, I believe is the right time) - I get an error message saying &quot;Undefined symbol&quot;.</p>
  <p>I thought it was a combination of forward declaration / includes / cross-dependencies, because I had this earlier in the project, but this seems not that.</p>
  <p>Just to be clear, if I make the declaration inline, it works absolutely fine.</p>
  <p>To try and find the cause, I made a copy of the Xcode project and removed all the classes one-by-one, all to no avail, so what I'm left with is this:</p>
  <p>main.cpp</p>
  <pre><code>#include &quot;print_string.hpp&quot;
  
  int main()
  {
      print_string x{};
      x.print_str(&quot;Hello!&quot;);
      x.sqr(5);
      
      return 0;
  }
  </code></pre>
  <p>print_string.cpp</p>
  <pre><code>#include &quot;print_string.hpp&quot;
  
  int print_string::sqr(int x)
  {
      return x * x;
  }
  </code></pre>
  <p>print_string.hpp</p>
  <pre><code>#ifndef print_string_hpp
  #define print_string_hpp
  
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  
  class print_string
  {
  public:
      void print_str(std::string str) { std::cout &lt;&lt; &quot;String: &quot; &lt;&lt; str &lt;&lt; std::endl; };
      int sqr(int x);
  };
  
  #endif
  </code></pre>
  <p>To try and resolve this issue, I thought I was doing something noddy, so I wrote a similar basic program (completely clean project) and it worked fine - so I think it may be my project that has broken, but I literally have nothing else left in this copy of the project other than the above. Cleaned the build folder, etc but not sure what else I can do.</p>
  <p>In summary, if I run this project with the <code>x.sqr(5);</code> call, I get the error. If I comment it out, it works absolutely fine.</p>