[Linker error]

Hello guys, I have a serious problem here.I am trying to understand why the following code gives so many Linker Errors (about 60!!!).
The errors are like:
[Linker error] undefined reference to `Point::Point()'
[Linker error] undefined reference to `Line::Line(Point, Point)'
[Linker error] undefined reference to `Point::move(double, double)'
[Linker error] undefined reference to `cwin'
[Linker error] undefined reference to `GraphicWindow::operator<<(Line)'
[Linker error] undefined reference to `Line::move(double, double)'
[Linker error] undefined reference to `WinMain@16'

...

So here is the code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include <vector>

using namespace std;

#include "ccc_win.h"

class Shape
{
public:
   Shape();
   virtual void plot() const;
   virtual Shape* make_shape(Point p) const;
};

Shape::Shape()
{
}

void Shape::plot() const
{
}

Shape* Shape::make_shape(Point p) const
{
   return NULL;
}

class Rectangle : public Shape
{
public:
   Rectangle();
   Rectangle(Point p, double l, double w);
   virtual Shape* make_shape(Point p) const;
   virtual void plot() const;
private:
   Point corner;
   double width;
   double height;
};

Rectangle::Rectangle()
{
}

Rectangle::Rectangle(Point p, double w, double h)
{
   corner = p;
   width = w;
   height = h;
}

Shape* Rectangle::make_shape(Point p) const
{
   return new Rectangle(p, 3, 2);
}

void Rectangle::plot() const
{
   Point p2 = corner;
   p2.move(0, height);
   Point p3 = corner;
   p3.move(width, 0);
   Line l1(corner, p2);
   Line l2(corner, p3);
   cwin << l1 << l2;
   l1.move(width, 0);
   l2.move(0, height);
   cwin << l1 << l2;
}

class Square : public Rectangle
{
public:
  Square();
  Square(Point p, double l);
  Shape* make_shape(Point p) const;
};

Square::Square()
{
}

Square::Square(Point p, double l) : Rectangle(p, l, l)
{ 
}

Shape* Square::make_shape(Point p) const
{
   return new Square(p, 2);
}

class Triangle : public Shape
{
public:
   Triangle();
   Triangle(Point p1, Point p2, Point p3);
   virtual Shape* make_shape(Point p) const;
   virtual void plot() const;
private:
   Point corner1;
   Point corner2;
   Point corner3;
};

Triangle::Triangle()
{
}

Triangle::Triangle(Point p1, Point p2, Point p3) 
{
   corner1 = p1;
   corner2 = p2;
   corner3 = p3;
}

Shape* Triangle::make_shape(Point p) const
{
   Point q = p;
   q.move(-1, 2);
   Point r = p;
   r.move(1, 2);
   return new Triangle(p, q, r);
}

void Triangle::plot() const
{
   cwin << Line(corner1, corner2);
   cwin << Line(corner2, corner3);
   cwin << Line(corner3, corner1);
}

class CircleShape : public Shape
{
public:
   CircleShape();
   CircleShape(Point p, double r);
   virtual Shape* make_shape(Point p) const;
   virtual void plot() const;
private:
   Point center;
   double radius;
};

CircleShape::CircleShape()
{
}

CircleShape::CircleShape(Point p, double r)
{
   center = p;
   radius = r;
}

Shape* CircleShape::make_shape(Point p) const
{
   return new CircleShape(p, 1);
}

void CircleShape::plot() const
{
   cwin << Circle(center, radius);
}

int ccc_win_main()
{
   cwin.coord(0, -1, 10, 9);
   vector<Shape*> icons;
   icons.push_back(new Rectangle(Point(0.1, 0.3), 0.8, 0.4));
   icons.push_back(new Square(Point(0.2, 1.2), 0.6));
   icons.push_back(new Triangle(Point(0.5, 2.3), Point(0.2, 2.7), Point(0.8, 2.7)));
   icons.push_back(new CircleShape(Point(0.5, 3.5), 0.4));

   int i;
   for (i = 0; i < icons.size(); i++)
   {
      Square(Point(0, i), 1).plot();
      icons[i]->plot();
   }
   Square(Point(0, i), 1).plot();
   cwin << Message(Point(0, i), "Quit");

   bool more = true;
   while (more)
   {
      Point p = cwin.get_mouse("Select shape");
      if (0 <= p.get_x() && p.get_x() <= 1
         && 0 <= p.get_y() && p.get_y() < icons.size() + 1)
      {
         int item = static_cast<int>(p.get_y());
         if (item == icons.size()) more = false;
         else 
         {
            p = cwin.get_mouse("Select location");
            icons[item]->make_shape(p)->plot();
         }
      }
   }
   return 0;
}
what you posted. Is it all in one file? The linker complains about object which are not present in that code. You need to add those files to you project where they are implemented.

Probably you're missing some (or all) required libraries in your settings of your project
What you mean by files?Libraries or what?I included ccc_win.h, and there is no problem with that.What else should I include?When it is compiled successfully on the console should appear four shapes - rectangle, triangle, circle and square.When the user click on one of those shapes, he/she should click again on the screen, and at the point where he/she clicked should appear the same object.
Is there a *.a or *.lib file that came with the file "ccc_win.h". This is just a header file and it appears that there are no implementations for some of the functions in it, such as "Point::Point()", hence your linker errors.

Alternatively, according to some site I just found about ccc_win, you are supposed to include two C++ source files as well. So we can best point you in the right direction, can you provide the link from where you downloaded ccc_win?
The link is from the textbook of Cay Horstmann: http://horstmann.com/bigcpp.html (in the section support materials-Source code for all sample programs and the CCC library)
When I include to the project ccc_asc, ccc_msw, ccc_shap, ccc_win and ccc_wxw, it gives an error :
wx/wx.h no such file or directory.It is included in ccc_wxw.cpp.What is this library?
I googled a little bit. That should answer your question: http://www.wright.edu/~dale.nelson/cs240/instructions.html
Yes, it helped me right away.I saw that I should include only a few of the files which i have included to the project. I must remove from the project : ccc_asc and ccc_wxw, then it compiled successfully.Thank you very much :)
I think it's something called wxWidgets - for cross platform GUIs.

The site I saw only said you needed to include the cpp files "ccc_msw.cpp" and "ccc_shap.cpp".

EDIT: Beat me to it coder! That was the site I found too ;)
Last edited on
Topic archived. No new replies allowed.