title: C++: Undefined symbols for architecture x86_64
body: <p>I have read most of the other posts with this title, but I could not find a solution.</p>
  
  <p>I have three files (I know the whole program doesn't make any sense, it is just for test purposes):</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include "Animal.h"
  
  Animal ape;
  
  int main(int argc, char *argv[]){
      ape.getRace();
  
      return 0;
  }
  </code></pre>
  
  <p>Animal.h</p>
  
  <pre><code>class Animal{
      public:
          int getRace();
      private:
          int race;
  };
  </code></pre>
  
  <p>Animal.cpp</p>
  
  <pre><code>#include "Animal.h"
  
  Animal::Animal(){
      race = 0;
  }
  
  int Animal::getRace(){
      race = 2;
      return race;
  }
  </code></pre>
  
  <p>When I run the main.cpp file I get this error:</p>
  
  <pre><code>Undefined symbols for architecture x86_64:
    "Animal::getRace()", referenced from:
        _main in main-oTHqe4.o
  ld: symbol(s) not found for architecture x86_64
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  [Finished in 0.1s with exit code 1]
  </code></pre>
  
  <p>What is wrong here?</p>