title: Weird Linker Error
body: <p>For some reason, i get a linker error. my distance.cpp compiles perfectly however same cannot be said for main.cpp this is the error i get:</p>
  
  <pre><code>Compiler: Default compiler
  Executing  g++.exe...
  g++.exe "C:\Users\Himalaya\Desktop\C++\testdistance\main.cpp" -o "C:\Users\Himalaya\Desktop\C++\testdistance\main.exe"    -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include"  -I"C:\Dev-Cpp\include\c++\3.4.2\backward"  -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32"  -I"C:\Dev-Cpp\include\c++\3.4.2"  -I"C:\Dev-Cpp\include"   -L"C:\Dev-Cpp\lib" 
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x13b):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x150):main.cpp: undefined reference to `Distance::setInches(double)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x16d):main.cpp: undefined reference to `Distance::Distance(int, double)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x18a):main.cpp: undefined reference to `Distance::Distance(int, double)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x19c):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x1af):main.cpp: undefined reference to `Distance::setFeet(int)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x1c6):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x1d8):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x1ea):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x1fc):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x3e1):main.cpp: undefined reference to `Distance::Distance(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x3fc):main.cpp: more undefined references to `Distance::Distance(Distance const&amp;)' follow
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x52a):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x54c):main.cpp: undefined reference to `Distance::operator+(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x598):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x5c0):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x5e8):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x7f8):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x81a):main.cpp: undefined reference to `Distance::operator-(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x866):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x88e):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x8b6):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xac7):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xb02):main.cpp: undefined reference to `Distance::operator+(Distance const&amp;)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xb97):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xc3a):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xdc9):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xe9f):main.cpp: undefined reference to `Distance::getInches()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xeb6):main.cpp: undefined reference to `Distance::getFeet()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xfcd):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xfd8):main.cpp: undefined reference to `Distance::Distance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xfe3):main.cpp: undefined reference to `Distance::getInches()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0xff4):main.cpp: undefined reference to `Distance::getFeet()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x101b):main.cpp: undefined reference to `Distance::getInches()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x102c):main.cpp: undefined reference to `Distance::getFeet()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x105d):main.cpp: undefined reference to `Distance::setInches(double)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x107a):main.cpp: undefined reference to `Distance::setInches(double)'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x10a0):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x10c8):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x10f0):main.cpp: undefined reference to `Distance::showDistance()'
  C:\Users\Himalaya\AppData\Local\Temp/cckxbaaa.o(.text+0x111b):main.cpp: undefined reference to `Distance::showDistance()'
  collect2: ld returned 1 exit status
  
  Execution terminated
  </code></pre>
  
  <p>Here is my codes;</p>
  
  <p>distance.cpp</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include "distance.h"
  
  using namespace std;
  
  
  
  Distance::Distance()
  {
      feet = 0;
      inches = 0;
  }
  
  Distance::Distance(int ft, double in)
  {
      this-&gt;feet = ft;
  
      if(in &gt;= 12)
      {
          while(in &gt;= 12) // pull as many feet as possible out of inches
          {
              this-&gt;feet += 1;
              in -= 12;
          }
          this-&gt;inches = in;  // store remainder
      }
      else
      {
          this-&gt;inches = in;
      }
  }
  
  Distance::Distance(const Distance &amp;dist)
  {
      this-&gt;feet = dist.feet;
      this-&gt;inches = dist.inches;
  }
  
  void Distance::setInches(double in)
  {
      if(in &gt;= 12)
      {
          while(in &gt;= 12) // pull as many feet as possible out of inches
          {
              this-&gt;feet += 1;
              in -= 12;
          }
          this-&gt;inches = in;  // store remainder
      }
      else
      {
          this-&gt;inches = in;
      }
  }
  
  double Distance::getInches()
  {
      return this-&gt;inches;
  }
  
  void Distance::setFeet(int ft)
  {
      this-&gt;feet = ft;
  }
  
  int Distance::getFeet()
  {
      return this-&gt;feet;
  }
  
  bool Distance::operator==(Distance &amp;dist)
  {
      if((this-&gt;feet == dist.feet) &amp;&amp; (this-&gt;inches == dist.inches))
      {
          return true;
      }
      else
      {
          return false;
      }
  }
  
  Distance Distance::operator+(const Distance &amp;dist)
  {
      Distance dist_return;
      double total_inches = 0;
      dist_return.feet = this-&gt;feet + dist.feet;
      total_inches = this-&gt;inches + dist.inches;
      if(total_inches &gt;= 12)
      {
          while(total_inches &gt;= 12) // pull as many feet as possible out of inches
          {
              dist_return.feet += 1;
              total_inches -= 12;
          }
          dist_return.inches = total_inches;
      }
      else
      {
          dist_return.inches = this-&gt;inches + dist.inches;
      }
  
      return dist_return;
  }
  
  Distance Distance::operator-(const Distance &amp;dist)
  {
      Distance dist_return;
      int temp_feet = this-&gt;getFeet(); // copy "this" so we can do math and show properly
      double temp_inches = this-&gt;getInches();
  
      dist_return.feet = temp_feet - dist.feet;
      dist_return.inches = temp_inches - dist.inches;
  
      dist_return.feet = abs(dist_return.feet);
      dist_return.inches = abs(dist_return.inches);  // distance is never negative, and - means difference, so 12 - 20 = 8
  
      return dist_return;
  }
  
  string Distance::showDistance()
  {
      string str_return = "";
      std::ostringstream temp_str_holder;
  
      if(this-&gt;feet &gt; 0)  // only print feet if we have any
      {
          temp_str_holder.str("");  // clear out ostringstream
          temp_str_holder &lt;&lt; this-&gt;feet;
          str_return += temp_str_holder.str();
  
          if(this-&gt;feet == 1)
          {
              str_return += " foot";
          }
          else
          {
              str_return += " feet";
          }
      }
  
      if(this-&gt;inches &gt; 0)  // only print inches if we have any
      {
          if(this-&gt;feet &gt; 0)
          {
              str_return += " ";  // if we have both feet and inches, print spacer between terms
          }
  
          temp_str_holder.str("");  // clear out ostringstream
          temp_str_holder &lt;&lt; this-&gt;inches;
          str_return += temp_str_holder.str();
  
          if(this-&gt;inches == 1)
          {
              str_return += " inch";
          }
          else
          {
              str_return += " inches";
          }
      }
  
      if((this-&gt;feet == 0) &amp;&amp; (this-&gt;inches == 0))  // if 0 feet 0 inches, just say 0 inches
      {
          str_return = "0 inches";
      }
  
      return str_return;
  }
  </code></pre>
  
  <p>distance.h    </p>
  
  <pre><code>#ifndef DISTANCE_H
  #define DISTANCE_H
  
  
  #include &lt;cmath&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  class Distance
  {
  private:
      double inches;
      int feet;
  
  public:
      Distance();
      Distance(int ft, double in);
      Distance(const Distance &amp;dist);
      void setInches(double in);
      double getInches();
      void setFeet(int ft);
      int getFeet();
      bool operator==(Distance &amp;dist);
      Distance operator+(const Distance &amp;dist);
      Distance operator-(const Distance &amp;dist);
      string showDistance();
  
  };
  
  #endif // DISTANCE_H
  </code></pre>
  
  <p>and my main.cpp which the program actually suppose to run from, however it gives me that weird error stated above.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;string&gt;
  #include "distance.h"
  
  
  using namespace std;
  
  void addDistances(Distance dist1, Distance dist2);
  void subtractDistances(Distance dist1, Distance dist2);
  void sumDistanceArray(Distance dist_array[]);
  void plotDistanceArray(Distance dist_array[]);
  void calcRectangle(Distance dist1, Distance dist2);
  //void calcVolume(Distance dist1, Distance dist2);
  
  int main()
  {
      Distance dist1;  // showing initialization using defaults
      dist1.setInches(6.7);
      Distance dist2(1,7);  // showing initialization to a distance
      Distance dist3(0,34);  // showing the auto-conversion of inches to feet as needed
      Distance dist4(dist3);  // showing initialization to another distance object's values
      dist4.setFeet(4);
      Distance dist_array[4] = {dist1, dist2, dist3, dist4};
      int menu_entry;
      bool menu_exit = false;
  
      do
      {
          //display menu
          cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; endl;
          cout &lt;&lt; "***** Main Menu *****" &lt;&lt; endl;
          cout &lt;&lt; "1: Add two distances" &lt;&lt; endl;
          cout &lt;&lt; "2: Subtract two distances" &lt;&lt; endl;
          cout &lt;&lt; "3: Sum an array of distances" &lt;&lt; endl;
          cout &lt;&lt; "4: Plot an array of distances" &lt;&lt; endl;
          cout &lt;&lt; "5: Calculate the perimeter and area and volume" &lt;&lt; endl;
          cout &lt;&lt; "6: Exit" &lt;&lt; endl;
          cout &lt;&lt; "Please enter the number of your selection: ";
          cin &gt;&gt; menu_entry;
  
  
          // check entry, warn and promt again if invalid
          if ((menu_entry &lt; 1) || (menu_entry &gt; 6))
          {
              cout &lt;&lt; endl;
              cout &lt;&lt; "Invalid entry! Please try again." &lt;&lt; endl;
              continue;
          }
  
  
          switch (menu_entry)
          {
              case 1:
                  addDistances(dist2, dist3);
                  break;
              case 2:
                  subtractDistances(dist2, dist3);
                  break;
              case 3:
                  sumDistanceArray(dist_array);
                  break;
              case 4:
                  plotDistanceArray(dist_array);
                  break;
              case 5:
                  calcRectangle(dist2, dist3);
                  break;
              case 6:
              default:
                  menu_exit = true;  
                  break;
          }
      }
      while(!menu_exit);
  
      return 0;
  }
  
  void addDistances(Distance dist1, Distance dist2)
  {
      Distance dist_total;
      dist_total = dist1 + dist2;
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "The sum of " &lt;&lt; dist1.showDistance() &lt;&lt; " and " &lt;&lt; dist2.showDistance() &lt;&lt; " is "
           &lt;&lt; dist_total.showDistance() &lt;&lt; endl;
  }
  
  void subtractDistances(Distance dist1, Distance dist2)
  {
      Distance dist_total;
      dist_total = dist1 - dist2;
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "The difference of " &lt;&lt; dist1.showDistance() &lt;&lt; " and " &lt;&lt; dist2.showDistance() &lt;&lt; " is "
           &lt;&lt; dist_total.showDistance() &lt;&lt; endl;
  }
  
  void sumDistanceArray(Distance dist_array[])
  {
      int i;
      int num_distances = 4;
      Distance dist_total;
      for(i=0; i&lt;num_distances; i++)
      {
          dist_total = dist_total + dist_array[i];
      }
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "The sum of: " &lt;&lt; endl;
      for(i=0; i&lt;num_distances; i++)
      {
          cout &lt;&lt; dist_array[i].showDistance() &lt;&lt; endl;
      }
      cout &lt;&lt; "is " &lt;&lt; dist_total.showDistance() &lt;&lt; endl;
  }
  
  void plotDistanceArray(Distance dist_array[])
  {
      int i;
      int j;
      double inches;
      double bar_percentage;  
      double bar_length;  
      int num_distances = 4;
      int num_feet_max = 6;  
      int num_max_disp_columns = 60;  
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "Plot of the array of distances : " &lt;&lt; endl;
  
      for(i=0; i&lt;num_distances; i++)
      {
          cout &lt;&lt; setw(20) &lt;&lt; dist_array[i].showDistance() &lt;&lt; " ";
  
          inches = dist_array[i].getInches() + (12 * dist_array[i].getFeet());
          bar_percentage = inches / (num_feet_max*12);
          bar_length = bar_percentage * num_max_disp_columns;  // calculate bar length
  
          for(j=0; j&lt;(bar_length+1); j++)
          {
              cout &lt;&lt; "#";  // draw bar
          }
          cout &lt;&lt; endl;
      }
  }
  
  void calcRectangle(Distance dist1, Distance dist2)
  {
      Distance rect_area;
      Distance rect_perimeter;
      double inches1;
      double inches2;
  
      inches1 = dist1.getInches() + (12 * dist1.getFeet());
      inches2 = dist2.getInches() + (12 * dist2.getFeet());
  
      rect_area.setInches(inches1 * inches2);
      rect_perimeter.setInches((2 * inches1) + (2 * inches2));
  
      cout &lt;&lt; endl;
      cout &lt;&lt; "A rectangle with dimensions " &lt;&lt; dist1.showDistance() &lt;&lt; " and " &lt;&lt; dist2.showDistance() &lt;&lt; " has an area of "
           &lt;&lt; rect_area.showDistance() &lt;&lt; " and a perimeter of " &lt;&lt; rect_perimeter.showDistance() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>what is the problem? what does cckxbaaa.o(.text+0x13b) mean?? This is something i have not encountered before that is why i am seeking for your help. All these 3 files are in the same folder/path, why does it giving me this error?</p>