Linker errors

I am having a lot of trouble with linker errors. I don't know what I am doing wrong. I am not even sure what files will help solve this. I have searched for the error codes but it isn't helping me. I haven't been programming long enough to understand it. Please help! I will give you any of my files you might want to see.

1>------ Build started: Project: monsters, Configuration: Debug Win32 ------
1> draw.cpp
1> Generating Code...
1> Skipping... (no relevant changes detected)
1> main.cpp
1>draw.obj : error LNK2019: unresolved external symbol "public: float __thiscall Arm::ArmGetLength(int)" (?ArmGetLength@Arm@@QAEMH@Z) referenced in function "void __cdecl DrawArm(class Arm)" (?DrawArm@@YAXVArm@@@Z)
1>draw.obj : error LNK2019: unresolved external symbol "public: float __thiscall Arm::ArmGetRad(int)" (?ArmGetRad@Arm@@QAEMH@Z) referenced in function "void __cdecl DrawArm(class Arm)" (?DrawArm@@YAXVArm@@@Z)
1>draw.obj : error LNK2019: unresolved external symbol "public: int __thiscall Arm::ArmGetLengthSize(void)" (?ArmGetLengthSize@Arm@@QAEHXZ) referenced in function "void __cdecl DrawArm(class Arm)" (?DrawArm@@YAXVArm@@@Z)
1>draw.obj : error LNK2019: unresolved external symbol "public: __thiscall Arm::Arm(float,float)" (??0Arm@@QAE@MM@Z) referenced in function "void __cdecl `dynamic initializer for 'test''(void)" (??__Etest@@YAXXZ)
1>C:\Users\Cody\documents\visual studio 2010\Projects\monsters\Debug\monsters.exe : fatal error LNK1120: 4 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


sorry I haven't really commented anything yet.
This is the draw.cpp

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
#ifndef DRAW
#define DRAW
#include "draw.h"
#include "Monster.h"

/************************
*functions				*
************************/

	Arm test(2, 1);

void DrawMonster() 
{	
	/********************
	*temp variable		*
	*move to config file*
	********************/
	int const MMax = 30; 

	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	glBegin(GL_QUADS);
	
		//draw each monster.
		for (int i = 0; i < MMax; i++)
		{
			monsterList(i);
		}
	
	glEnd();
	glFlush();
}


void monsterList(int M) //draws one monster
{
	DrawArm(test);
}

void DrawArm(Arm arm)
{
	for (int i = 0; i < arm.ArmGetLengthSize(); i++)
	{
		for (float theta = 0; theta < 360; theta+=22.5)
		{
			float x = arm.ArmGetRad(i);
			float a = x*cos(theta);
			glVertex3f(a, sqrt((x*x) - (a*a)), 0);
			glVertex3f(a, sqrt((x*x) - (a*a)), -arm.ArmGetLength(i));
			a = x*cos(theta + 22.5);
			glVertex3f(a, sqrt((x*x) - (a*a)), 0);
			glVertex3f(a, sqrt((x*x) - (a*a)), -arm.ArmGetLength(i));
		}	
	}
}
#endif 


this is draw.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


#include "Monster.h"
#include <glut.h>


#ifndef MONSTER_DRAW_H
#define MONSTER_DRAW_H

void monsterList(int M);

void DrawMonster();
void DrawArm(Arm arm);
void DrawLeg();
void DrawBody();
void DrawHead();
#endif



closed account (48T7M4Gy)
You haven't included the code for various Arm class methods including the Arm constructor, ArmGetLength(int), ArmGetRad(int) etc. Presumably Arm is a class you have on separate files. If so they need to be #include'd in draw.h Atleast the Arm.h file that is.
Last edited on
yeah the class is included in the monster.h file
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
201
202
203
#include <vector>

using namespace std;

#ifndef MONSTER_MONSTER_H
#define MONSTER_MONSTER_H

class Head
{
private:
	float noseLength;
	float noseWidthBack;
	float noseWidthMid;
	float noseWidthFront;
	float noseHightBack;
	float noseHightMid;
	float noseHightFront;

	float eyeWidth;
	float eyeHight;
	float pupilWidth;
	float pupilHight;

	float earWidth;
	float earLength;
	float earHight;
	float earCurve;

	float mouthWidth;
	float mouthDepth;

	float headTopWidth;
	float headMidWidth;
	float headBotWidth;
	float headTopDepth;
	float headMidDepth;
	float headBotDepth;

public:
	Head(void);

	float getNoseLength(void);
	float getNoseWidthBack(void);
	float getNoseWidthMid(void);
	float getNoseWidthFront(void);
	float getNoseHightBack(void);
	float getNoseHightMid(void);
	float getNoseHightFront(void);

	float getEyeWidth(void);
	float getEyeHight(void);
	float getPupilWidth(void);
	float getPupilHight(void);

	float getEarWidth(void);
	float getEarLength(void);
	float getEarHight(void);
	float getEarCurve(void);

	float getMouthWidth(void);
	float getMouthDepth(void);

	float getHeadTopWidth(void);
	float getHeadMidWidth(void);
	float getHeadBotWidth(void);
	float getHeadTopDepth(void);
	float getHeadMidDepth(void);
	float getHeadBotDepth(void);

	void setNoseLength(float);
	void setNoseWidthBack(float);
	void setNoseWidthMid(float);
	void setNoseWidthFront(float);
	void setNoseHightBack(float);
	void setNoseHightMid(float);
	void setNoseHightFront(float);

	void setEyeWidth(float);
	void setEyeHight(float);
	void setPupilWidth(float);
	void setPupilHight(float);

	void setEarWidth(float);
	void setEarLength(float);
	void setEarHight(float);
	void setEarCurve(float);

	void setMouthWidth(float);
	void setMouthDepth(float);

	void setHeadTopWidth(float);
	void setHeadMidWidth(float);
	void setHeadBotWidth(float);
	void setHeadTopDepth(float);
	void setHeadMidDepth(float);
	void setHeadBotDepth(float);
};

class Leg
{
private:
	vector<float> length;
	vector<float> rad;
	vector<int> bodyPos;

public:
	Leg();

	void addLeg(float l, float r, int p);

	float getLegLength(int legNum);
	float getLegRad(int legNum);
	int getPos(int legNum);

	void setLegLength(int legNum, float cur);
	void setLegRad(int legNum, float cur);
	void setPos(int legNum, int cur);
};

class Hand
{
private:
	float palmLength;
	float palmWidth;
	vector<float>	fingerLength;
	vector<float>	fingerRad;
	vector<int>		fingerPos;

public:
	Hand();
	
	void addHand(float l, float w, int p);
	void addFinger(float l, float w, int p);

	float getPalmLength(void);
	float getPalmWidth(void);

	void setPalmLength(float l);
	void setPalmWidth(float w);

	float getFingerLength(void);
	float getFingerRad(void);

	void setFingerLength(int finger, float cur);
	void setFingerRad(int finger, float cur);
};

class Arm
{
private:
	vector<float> length;
	vector<float> rad;
	vector<Hand> hands;

public:
	Arm();
	Arm(float lengthSet, float radSet);
	int ArmGetLengthSize();
	float ArmGetLength(int i);

	int ArmGetRadSize();
	float ArmGetRad(int i);

};

class Body
{
private:
	float colorR;
	float colorG;
	float colorB;
	vector<int> Spine;
	vector<Leg> Legs;
	vector<Arm> Arms;
	bool BODY;

public:
	Body();

	void addArm(int );

};

class Monster
{
private:
	int Age;
	Body	B;
	Head	H;
	float	posX;
	float	posY;
	float	posZ;
	float	size;

public:
	Monster();

	Monster getM(int num);
	void	Grow();

};

#endif 
try #include "Arm.h" in draw.h file.
Also, if draw.cpp is in a different dll than class Arm, you have to export class Arm.

class __declspec(dllexport) Arm
{
//.......
};
closed account (48T7M4Gy)
#include "monster.h" wherever you are using any of the funtionality or classes in that file. Arm.cpp will also need that # include as well by the look of it, again assuming you own the source code.

The linker needs to be told exactly where to go looking for the bits and pieces you are referring to.

Over all it might make more sense to separate out the files so that 1 file = 1 class header with corresponding dedicated .cpp files. This makes it easier to manage. :)
Looks like you didn't put the source code for the Arm class into project.
Or, you forgot to implement the methods in Arm class.
@kemort:
This isn't going to be about header files. If that was the problem, then the OP would have compilation errors. These are linker errors.

The problem is that the linker can't find the implementation of those Arm methods. As liuyang said, either they're not implemented, or else the project/makefile hasn't been set up properly to link against them.
closed account (48T7M4Gy)
http://www.cprogramming.com/tutorial/compiler_linker_errors.html
http://stackoverflow.com/questions/14557657/linker-error-c-undefined-reference
http://stackoverflow.com/questions/19486878/linker-error-error-lnk2019-unresolved-external-symbol
Last edited on
ok I am going to separate all of the classes and see if that helps. I thought it would be easier to write them in one file and test it but I am having more problems than when I start with them separated. Visual studios was doing something weird with my Monster.cpp file, when I started separating them it found a bunch of things that I am surprised didn't cause compiler errors. I guess if this doesn't help I will be back. Thanks everybody!
I have everything cleared up that I was getting but it is throwing a new linker error now.
fatal error LNK1561: entry point must be defined
from the stuff I have found on the internet this error is when you don't have a main function. which doesn't help me.
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

#include <iostream>
#include "draw.h"

namespace Wall
{
	void Initialize() {
		glClearColor(0.0, 0.0, 0.0, 0.0);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
	}

	int main(int iArgc, char** cppArgv) {

		//*vector<Monster> monsters;


		glutInit(&iArgc, cppArgv);
		glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
		glutInitWindowSize(250, 250);
		glutInitWindowPosition(200, 200);
		glutCreateWindow("Monster");
		Initialize();

		glutDisplayFunc(DrawMonster);

		glutMainLoop();
		return 0;
	}
}
closed account (48T7M4Gy)
Review the extent of your namespace Wall. The entry point is main() and the linker can't find it becuase of the namespace.

http://stackoverflow.com/questions/3956678/main-in-namespace
Since you're using Visual Studio 2010, I assume you started a Win32 Application, not a Win32 Console Application.

I don't have a Visual Studio with me currently. So maybe you can try create another Win32 project, and select Console Application in the first wizard screen. Make sure you selected Empty Project option.
Topic archived. No new replies allowed.