导致此LNK2019未解决的外部符号错误的原因是什么?

时间:2015-01-08 15:38:40

标签: c++ linker-errors lnk2019 unresolved-external

我一直想弄清楚如何解决这个问题,但我根本看不出有什么问题。错误消息如下;

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

我环顾网络,它提到我可能正在使用'Circle'来定义它的方式,但我似乎无法发现它,所以任何帮助都会非常感激。下面是treeBranch.cpp和.h文件以及Circle.h文件。

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);

};

1 个答案:

答案 0 :(得分:1)

你需要实现那些方法,例如我没有看到Circle :: Circle()的实现,以及render函数,你是否忘记编译并将Circle.cpp添加到链接? 那些是连锁错误。