title: undefined reference to constructors and destructors
body: <p>I've only seen this caused by people not linking their class objects together at build time, but I have, and I'm unsure what the matter is.</p>
  
  <p>the source:</p>
  
  <pre><code>//test.cpp
  #include "Point.h"
  #include "Sphere.h"
  #include "Scene.h"
  
  
  int main(){
      Sphere s;
      Scene sc;
      sc.img_plane.upper_left = Point(-1, 1, -3);
      sc.img_plane.upper_right = Point(1, 1, -3);
      sc.img_plane.lower_left = Point(-1, -1, -3);
      sc.img_plane.lower_right = Point(1, -1, -3);
      sc.width = 100;
      sc.height = 100;
      return 0;
  }
  </code></pre>
  
  <p>the error:</p>
  
  <pre><code>test.cpp:(.text+0x17): undefined reference to `Sphere::Sphere()'
  test.cpp:(.text+0x26): undefined reference to `Scene::Scene()'
  test.cpp:(.text+0x192): undefined reference to `Scene::~Scene()'
  test.cpp:(.text+0x1a1): undefined reference to `Sphere::~Sphere()'
  test.cpp:(.text+0x1bf): undefined reference to `Scene::~Scene()'
  test.cpp:(.text+0x1d3): undefined reference to `Sphere::~Sphere()'
  </code></pre>
  
  <p>the Makefile:</p>
  
  <pre><code>CC = g++
  SRC = ./src
  BUILD = ./build
  
  main : main.o Point.o colort.o Sphere.o Scene.o Ray.o HitRecord.o
      $(CC) $(BUILD)/main.o $(BUILD)/Point.o -o $(BUILD)/main
  
  main.o : $(SRC)/test.cpp
      $(CC) -c $&lt; -o $(BUILD)/main.o
  
  Point.o : $(SRC)/Point.cpp $(SRC)/Point.h
      $(CC) -c $&lt; -o $(BUILD)/Point.o
  
  colort.o : $(SRC)/colort.cpp $(SRC)/colort.h
      $(CC) -c $&lt; -o $(BUILD)/colort.o
  
  Sphere.o : $(SRC)/Sphere.cpp $(SRC)/Sphere.h $(SRC)/colort.cpp $(SRC)/Point.cpp
      $(CC) -c $&lt; -o $(BUILD)/Sphere.o
  
  ImagePlane.o : $(SRC)/ImagePlane.cpp $(SRC)/ImagePlane.h
      $(CC) -c $&lt; -o $(BUILD)/ImagePlane.o
  
  Scene.o : $(SRC)/Scene.cpp $(SRC)/Scene.h
      $(CC) -c $&lt; -o $(BUILD)/Scene.o 
  
  Ray.o : $(SRC)/Ray.cpp $(SRC)/Ray.h
      $(CC) -c $&lt; -o $(BUILD)/Ray.o
  
  HitRecord.o : $(SRC)/HitRecord.cpp $(SRC)/HitRecord.h
      $(CC) -c $&lt; -o $(BUILD)/HitRecord.o     
  
  clean :
      rm $(BUILD)/*
  
  test : main 
      $(BUILD)/main
  </code></pre>
  
  <p>Scene constructor is the same as the Sphere:</p>
  
  <p>Sphere.h:</p>
  
  <pre><code>#ifndef SPHERE_H_
  #define SPHERE_H_
  
  #include "colort.h"
  #include "Point.h"
  #include "Ray.h"
  
  class Sphere {
  public:
      Sphere();
      virtual ~Sphere();
      Point center;
      double radius;
      color_t diffuse, specular;
      double intersection(Ray r);
  };
  
  #endif /* SPHERE_H_ */
  </code></pre>
  
  <p>Sphere.cpp:</p>
  
  <pre><code>#include "Sphere.h"
  
  #include &lt;math.h&gt;
  
  Sphere::Sphere() {
  
  }
  
  Sphere::~Sphere() {
  
  }
  
  ...other class functions
  </code></pre>