I’m now studying Fundamentals Of Data Structures in C++ written by Ellis Horowitz, trying to implement the example on the page 77. However, after I build the project, Eclipse Console shows up some warning.
Here’s my header file:
#ifndef RECTANGLE_H_
#define RECTANGLE_H_
class Rectangle{
public:
Rectangle();
~Rectangle();
int GetHeight();
int GetWidth();
private:
int xLow, yLow, height, width;
} ;
#endif
And here’s my source file:
#include <iostream>
#include "Rectangle.h"
using namespace std;
int main(){
Rectangle r, s;
Rectangle *t = &s;
if(r.GetHeight()*r.GetWidth() > t->GetHeight()*t->GetWidth())
cout << "r";
else
cout << "s";
cout << "has the greater area" << endl;
return 0;
}
And the CDT Build Console shows:
Building target: rectangle
Invoking: MacOS X C++ Linker
g++ -o "rectangle" ./main.o
Undefined symbols:
"Rectangle::Rectangle()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetWidth()", referenced from:
_main in main.o
_main in main.o
"Rectangle::GetHeight()", referenced from:
_main in main.o
_main in main.o
"Rectangle::~Rectangle()", referenced from:
_main in main.o
_main in main.o
_main in main.o
_main in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rectangle] Error 1
**** Build Finished ****
Besides, will binary files automatically created after building the project?
The implementations to your Rectangle methods are really missing.
That are the methods, you see in the linker error messages:
If you have a Rectangle.cpp (or .cc, .cxx) file, than you need to compile this also and link the Rectangle.o file.
since you asked, here a simplified overview, what different filename ending are for: