Search code examples
c++linker-errorslnk2019unresolved-external

What is causing this LNK2019 Unresolved external symbol error?


I've been trying to figure out how to fix this, but I simply cannot see what is wrong. The error message(s) are as follows;

error LNK2019: unresolved external symbol "public:_thiscall Circle::Circle(coid)" (??0Circle@@QAE@XZ) reference in function "public:_thiscall treeBranch::treeBranch(void)" (??0treeBranch@@QAE@XZ)

error LNK2019: unresolved external symbol "public: void_thiscall Circle::render(void)" (...) referenced in function "public: void_thiscalltreeBranch::renderTreeBranch(float,float,float,float)" (...)

error LNK1120: 2 unresolved externals

I've looked around the web, and it mentioned I may be using 'Circle' differently to how it was defined, but I can't seem to spot it, so any help would be greatly appreciated. Below is the treeBranch.cpp and .h file as well as the Circle.h file.

treeBranch.cpp

#include "stdafx.h"
#include "treeBranch.h"
#include "Circle.h"

using namespace std;
using namespace CoreStructures;


treeBranch::treeBranch() {

trunkComponent = new Circle();

// Load texture images
treeTexture = wicLoadTexture(wstring(L"\\Textures\\Trunk.png"));

// Load shaders that make up the snowmanShader program
treeShader = setupShaders(string("Shaders\\basic_vertex_shader.txt"), string("Shaders\\texture_fragment_shader.txt"));

// Setup uniform locations
locT = glGetUniformLocation(treeShader, "T");
}



// Render snowman object.  x, y represent the position of the snowman's body, scale determines the scale of the snowman and orientation is the angle of the snowman (in degrees)
void treeBranch::renderTreeBranch(float x, float y, float scale, float orientation) {

// "Plug in" the snowman shader into the GPU
glUseProgram(treeShader);


// 1. Draw the main body

// Create matrices based on input parameters
GUMatrix4 bodyTransform = GUMatrix4::translationMatrix(x, y, 0.0f) *
    GUMatrix4::rotationMatrix(0.0f, 0.0f, orientation*gu_radian) *
    GUMatrix4::scaleMatrix(scale, scale, 1.0f);

// Upload body transform to shader
glUniformMatrix4fv(locT, 1, GL_FALSE, (GLfloat*)&bodyTransform);

// Use the snow texture for the main body
glBindTexture(GL_TEXTURE_2D, treeTexture);

// Draw the circle for the body
trunkComponent->render();



// 2. draw head

// - Setup the RELATIVE transformation from the centre of the body to where the head's origin will be
// - Like the body, the head uses the same circle model so the origin will be in the middle of the head
// - Offsets are calculated in terms of the parent object's modelling coordinates.  Any scaling, rotation etc. of the parent will be applied later in the matrix sequence.
// - This makes relative modelling easier - we don't worry about what transforms have already been applied to the parent.
GUMatrix4 body_to_head_transform = GUMatrix4::translationMatrix(0.0f, 1.25f, 0.0f) * GUMatrix4::scaleMatrix(0.65f, 0.65f, 1.0f);

// Since we're working with a relative transform, we must multiply this with the parent objects's (that is, the body's) transform also
// REMEMBER: THE RELATIVE TRANSFORM GOES LAST IN THE MATRIX MULTIPLICATION SO IT HAPPENS FIRST IN THE SEQUENCE OF TRANSFORMATIONS
GUMatrix4 headTransform = bodyTransform * body_to_head_transform;

// Upload the final head transform to the shader
glUniformMatrix4fv(locT, 1, GL_FALSE, (GLfloat*)&headTransform);

// Bind the head texture
glBindTexture(GL_TEXTURE_2D, treeTexture);

// Draw the circle for the head
trunkComponent->render();
}

treeBranch.h

#pragma once

#include <glew\glew.h>
#include <freeglut\freeglut.h>
#include <CoreStructures\CoreStructures.h>
#include "texture_loader.h"
#include "shader_setup.h"
#include "Circle.h"

class Circle;

class treeBranch {

// Snowman made up of multiple circle objects (we store just one instance and render this multiple times)
Circle *trunkComponent;

// Textures for snowman body and head
GLuint treeTexture;

// Shader program for drawing the snowman
GLuint treeShader;

// Uniform variable locations in snowmanShader
GLuint locT;


public:

// Default constructor
treeBranch();

// Render snowman object.  x, y represent the position of the snowman's body, scale determines the scale of the snowman and orientation is the angle of the snowman (in degrees)
void renderTreeBranch(float x, float y, float scale, float orientation);

};

Circle.h

#pragma once

#include <glew\glew.h>
#include <freeglut\freeglut.h>
#include <CoreStructures\CoreStructures.h>
#include "texture_loader.h"
#include "shader_setup.h"


class Circle {

// Variables to represent the VBO and VAO of the circle object
GLuint circleVAO, vertexPositionVBO, texCoordVBO;

public:

// Default constructor - setup circle with unit radius
Circle();

// Render circle - all relevant transformations are assumed to be setup before calling this function
void render(void);

};

Solution

  • You need to implement those methods, for example I don't see the implementation of Circle::Circle(), as well as the render function, have you forgotten to compile and add Circle.cpp to the linkage? those are the linkage errors.