title: Can't link header files to my main.cpp in VScode (macOS) (clang error)
body: <p>I am trying to link a header file which has a class defined in it and a .cpp file that has the actual functions of that class to my main cpp file but I'm getting this error:</p>
  <p>c++     DataMembers.cpp   -o DataMembers
  Undefined symbols for architecture x86_64:
  &quot;Cat::eat()&quot;, referenced from:
  _main in DataMembers-053507.o
  &quot;Cat::meow()&quot;, referenced from:
  _main in DataMembers-053507.o
  &quot;Cat::sleep()&quot;, referenced from:
  _main in DataMembers-053507.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  make: *** [DataMembers] Error 1</p>
  <p>Please note that all files exists in the same directory!</p>
  <p>my main.cpp code is:</p>
  <pre class="lang-cpp prettyprint-override"><code>
  #include &quot;Cat.h&quot;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      Cat myCat;
  
      myCat.eat();
      myCat.meow();
      myCat.sleep();
  }
  
  </code></pre>
  <p>my Cat.h code:</p>
  <pre class="lang-cpp prettyprint-override"><code>#ifndef CAT_H_
  #define CAT_H_
  
  class Cat 
  {
  public:
      void meow();
      void sleep();
      void eat();
  };
  
  #endif
  
  </code></pre>
  <p>and Cat.cpp code is:</p>
  <pre class="lang-cpp prettyprint-override"><code>
  #include &lt;iostream&gt;
  #include &quot;Cat.h&quot;
  using namespace std;
  
  void Cat::meow()
  {
      cout &lt;&lt; &quot;Meowwwwww!&quot; &lt;&lt; endl;
      return;
  }
  
  void Cat::sleep()
  {
      cout &lt;&lt; &quot;Zzz ... &quot; &lt;&lt; endl;
      return;
  }
  
  void Cat::eat()
  {
      cout &lt;&lt; &quot;Num Nom Nom .. Yummy&quot; &lt;&lt; endl;
      return;
  }
  
  </code></pre>
  <p>Interesting thing is when I change the header file in my main.cpp from <code>#inclue &quot;Cat.h&quot;</code>
  into <code>#include &quot;Cat.cpp&quot;</code> the program compiles without any issues! I just don't know why?</p>
  <p>I have searched for a solution but couldn't find any yet! and I need to be able to use header files I create myself!</p>
  <p>Thank you in advance friends!</p>