是什么导致了这个 LNK2019 Unresolved external symbol 错误?

What is causing this LNK2019 Unresolved external symbol error?

我一直在想办法解决这个问题,但我就是看不出哪里出了问题。报错信息如下;

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

};

你需要实现那些方法,比如我没看到Circle::Circle()的实现,还有render函数,你是不是忘了编译加上Circle.cpp联系? 这些是链接错误。