OpenGL code won't complie LNK2019

Jan 16, 2014 at 7:17am
/////
// error code
Error 2 error LNK2019: unresolved external symbol "public: __thiscall Color::Color(void)" (??0Color@@QAE@XZ) referenced in function "public: __thiscall ColorChangeCode::ColorChangeCode(void)" (??0ColorChangeCode@@QAE@XZ) C:\Users\O\Desktop\SloanP1\SloanP1v2\SloanP1v2\ColorChangeCode.obj

//Driver//
// BounceDriver.cpp

#include <windows.h> // Must have for Windows platform builds
#include <gl\gl.h> // Microsoft OpenGL headers (version 1.1 by themselves)
#include <gl\glu.h> // OpenGL Utilities
#include <gl\glut.h> // Glut (Free-Glut on Windows)
#include "Bounce.h"
#include "Color.h" <- keep in mind the program will compile without
color or colorchangecode included
#include "ColorChangeCode.h" <- where the above error reports the problem
seems to be in the constructor()
using namespace std;

GLfloat x = 0.0f;
GLfloat y = 0.0f;
GLfloat rsize = 25;


GLfloat xstep = 1.0f;
GLfloat ystep = 1.0f;


GLfloat windowWidth;
GLfloat windowHeight;

////////
// Main program entry point
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(500,500);
glutCreateWindow("Ryan Sloan - SloanP1");
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);
glutTimerFunc(33, TimerFunction, 1);

SetupRC();

glutMainLoop();

return 0;
}
/////////
//Bounce.cpp


//windows.h gl glu and glut included
#include "ColorChangeCode.h"
#include "Color.h"
#include "Bounce.h"

using namespace std;

extern GLfloat x;
extern GLfloat y;
extern GLfloat rsize;


extern GLfloat xstep;
extern GLfloat ystep;

extern GLfloat windowWidth;
extern GLfloat windowHeight;

GLfloat sizeOfTeapot = 15.0f;



void RenderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
//Draw Grey rectangle at +/-200
glColor3f(.50, .50, .50);
glRecti(-200, 200, 200, -200);
//Draw white rectangle at +/-100
glColor3f(1.0f, 1.0f, 1.0f);
glRecti(-100, 100, 100, -100);
//Set drawing color
// R G B
glColor3f(1.0f, 0.5f, 0.0f);
//draws a orange teapot
glutWireTeapot(sizeOfTeapot);
//set drawing color
// Set current drawing color to blue
// R G B
glColor3f(0.0f, 0.0f, 1.0f);

// Draw a filled rectangle with current color
glRectf(x, y, x + rsize, y - rsize);


glColor3f(0.5f, 0.5f, 0.5f);

glLineWidth(1.5);

glBegin(GL_LINES);
//x and y axis
glVertex3f(0.0, 200, 0.0);
glVertex3f(0.0, -200, 0.0);
glVertex3f(200, 0.0, 0.0);
glVertex3f(-200, 0.0, 0.0);

glEnd();

glutSwapBuffers();
}

//
void TimerFunction(int value)
{

GLfloat windowWidth = 100, windowHeight = 100;

if(x > windowWidth-rsize || x < -windowWidth)
xstep = -xstep;


if(y > windowHeight || y < -windowHeight + rsize)
ystep = -ystep;

// Actually move the square
x += xstep;
y += ystep;


if(x > (windowWidth-rsize + xstep))
x = windowWidth-rsize-1;
else if(x < -(windowWidth + xstep))
x = -windowWidth -1;

if(y > (windowHeight + ystep))
y = windowHeight-1;
else if(y < -(windowHeight - rsize + ystep))
y = -windowHeight + rsize - 1;

// add mouse check here
glutMouseFunc(ChangeColorOrSpeed); <- where the action is,
colorchangecode is declared
inside of
changeColorOrSpeed



glutPostRedisplay();
glutTimerFunc(33,TimerFunction, 1);
}




void SetupRC(void)
{

glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}



void ChangeSize(int w, int h)
{
GLfloat aspectRatio;

// Prevent a divide by zero
if(h == 0)
h = 1;

// Set Viewport to window dimensions
glViewport(0, 0, w, h);

// Reset coordinate system
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

// Establish clipping volume (left, right, bottom, top, near, far)
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
{
windowWidth = 100;
windowHeight = 100 / aspectRatio;
glOrtho (-100.0, 100.0, -windowHeight, windowHeight, 1.0, -1.0);
}
else
{
windowWidth = 100 * aspectRatio;
windowHeight = 100;
glOrtho (-windowWidth, windowWidth, -100.0, 100.0, 1.0, -1.0);
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void ChangeColorOrSpeed(GLint button, GLint state, GLint x, GLint y)
{
ColorChangeCode execute;
static GLint indeXA = 0;

if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN ){
glBegin(GL_POLYGON);
//cycle through the colors;
glColor3f(execute.colors[indeXA].getR(),
execute.colors[indeXA].getG(),
execute.colors[indeXA].getB());
// Draw a filled rectangle with current color
glRecti(x, y, x + rsize, y - rsize);
glEnd();
++indeXA;
if (indeXA == 6){
indeXA = 0;
}

}

}


//ColorChangeCode.h
//windows.h, gl, glu,and glut were all included
#include "Color.h"

using namespace std;
#ifndef _COLORCHANGECODE_H
#define _COLORCHANGECODE_H

class ColorChangeCode : public Color {

public:
Color* colors; <------------------ I think the problem is here.
When I comment out this class and
the color class it will compile.
Otherwise, I get LNK2019
ColorChangeCode();
~ColorChangeCode(){ delete[] colors;}
};




#endif
////
//ColorChangeCode.cpp
//windows.h, gl, glu,and glut were all included
#include "Color.h"
#include "ColorChangeCode.h"

ColorChangeCode::ColorChangeCode()
{
colors = new Color[6];
colors[0].setRed();
colors[1].setOrange();
colors[2].setYellow();
colors[3].setGreen();
colors[4].setBlue();
colors[5].setPurple();
}

//Color.h
//windows.h, gl, glu,and glut were all included

#ifndef _COLOR_H
#define _COLOR_H



class Color {
GLfloat R;
GLfloat G;
GLfloat B;

public:
Color();
void setRed();
void setOrange();
void setYellow();
void setGreen();
void setBlue();
void setPurple();
GLfloat getR(){return R;}
GLfloat getG(){return G;}
GLfloat getB(){return B;}
};
#endif
///////////////////////////////////
//Color.cpp
//windows.h, gl, glu,and glut were all included
#include "Color.h"

void Color::setRed(){

R = 1.0f;
G = 0.0f;
B = 0.0f;

}
void Color::setOrange(){

R = 1.0f;
G = .50f;
B = 0.0f;


}
void Color::setYellow(){

R = .50f;
G = 1.0f;
B = .50f;

}
void Color::setGreen(){

R = 0.0f;
G = .50f;
B = 1.0f;

}
void Color::setBlue(){

R = 0.0f;
G = 0.0f;
B = 1.0f;

}
void Color::setPurple(){

R = 0.0f;
G = 0.0f;
B = .50f;

}
Any help you can give to shed some light on why it will not compile when colorchangecode and color are included and instanciated. Thanks

Jan 16, 2014 at 8:00am
Use code tags !!!111 please!

That line calls the constructor of class Color
colors = new Color[6];

You have declared that constructor in class Color:
Color();

but you haven't defined it in cpp
Jan 16, 2014 at 8:04am
Jan 16, 2014 at 9:55am
awesome thank you! what are code tags?
Jan 16, 2014 at 11:34am
awesome thank you! what are code tags?


http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.