0

I just started looking at the basics of openGL, but I keep getting error LNK2019 and I don't know what's causing it or how to fix it.

#include "stdafx.h"
#include <cstdlib>
#include <GLTools.h>
#include <GLShaderManager.h>

//Include OpenGL header files, so that we can use OpenGL
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

using namespace std;

GLBatch         a;
GLShaderManager b;

//Called when a key is pressed
void handleKeypress(unsigned char key, int x, int y){
    switch(key){
        case 27: //Escape key
            exit(0);
    }
}

//Initializes 3D rendering
void initRendering(){
    glEnable(GL_DEPTH_TEST);
}

//Called when the window is resized
void handleResize(int w, int h){
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}

//Draws the 3D scene
void drawScene(){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
    glLoadIdentity(); //Reset the drawing perspective

    GLfloat colour[] = {1.0f, 0.0f, 0.0f, 1.0f};
    b.UseStockShader(GLT_SHADER_IDENTITY, colour);
    a.Draw();

    glutSwapBuffers(); //Draw the scene on the screen
}
//Only called once, in main
void setupScene(){
    glClearColor(0.98f, 0.625f, 0.12f, 1.0f);
    b.InitializeStockShaders();
    GLfloat vertices[] = {0.0f, 0.0f, 0.0f,
                          0.0f, 1.0f, 0.0f,
                          1.0f, 0.0f, 0.0f};
    a.Begin(GL_TRIANGLES, 3);
    a.CopyVertexData3f(vertices);
    a.End();
}
int main(int argc, char** argv){
    //Initialize GLUT
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(400, 400);

    //Create the window
    glutCreateWindow("Window name");
    initRendering();

    //Set handler functions
    glutDisplayFunc(drawScene);
    glutKeyboardFunc(handleKeypress);
    glutReshapeFunc(handleResize);

    setupScene();

    glutMainLoop();
    return 0;
}

Errors:

1>gltools test.obj : error LNK2019: unresolved external symbol "public: virtual void __thiscall GLBatch::Draw(void)" (?Draw@GLBatch@@UAEXXZ) referenced in function "void __cdecl drawScene(void)" (?drawScene@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: int __cdecl GLShaderManager::UseStockShader(enum GLT_STOCK_SHADER,...)" (?UseStockShader@GLShaderManager@@QAAHW4GLT_STOCK_SHADER@@ZZ) referenced in function "void __cdecl drawScene(void)" (?drawScene@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::End(void)" (?End@GLBatch@@QAEXXZ) referenced in function "void __cdecl setupScene(void)" (?setupScene@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::Begin(unsigned int,unsigned int,unsigned int)" (?Begin@GLBatch@@QAEXIII@Z) referenced in function "void __cdecl setupScene(void)" (?setupScene@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: bool __thiscall GLShaderManager::InitializeStockShaders(void)" (?InitializeStockShaders@GLShaderManager@@QAE_NXZ) referenced in function "void __cdecl setupScene(void)" (?setupScene@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::CopyVertexData3f(float (*)[3])" (?CopyVertexData3f@GLBatch@@QAEXPAY02M@Z) referenced in function "public: void __thiscall GLBatch::CopyVertexData3f(float *)" (?CopyVertexData3f@GLBatch@@QAEXPAM@Z)
1>gltools test.obj : error LNK2019: unresolved external symbol "void __cdecl gltSetWorkingDirectory(char const *)" (?gltSetWorkingDirectory@@YAXPBD@Z) referenced in function _main
1>gltools test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLBatch::GLBatch(void)" (??0GLBatch@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'a''(void)" (??__Ea@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLShaderManager::GLShaderManager(void)" (??0GLShaderManager@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'b''(void)" (??__Eb@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall GLBatch::~GLBatch(void)" (??1GLBatch@@UAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'a''(void)" (??__Fa@@YAXXZ)
1>gltools test.obj : error LNK2019: unresolved external symbol "public: __thiscall GLShaderManager::~GLShaderManager(void)" (??1GLShaderManager@@QAE@XZ) referenced in function "void __cdecl `dynamic atexit destructor for 'b''(void)" (??__Fb@@YAXXZ)

Anyone know why this is happening?

2
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by ben1996123
0

you have to add some openGL libraries. Look in openGL docs for one of those functions and it should tell you what libraries you have to use.

0

I tried that but I still can't figure out how to fix it. It's not letting me create any arrays. I tried dynamically allocating the memory but it still didn't work :/

It allowed me to create the same array in main, but not in setupScene.

0

Hmm, I remade the project and copied everything the book said but now I'm getting "Unhandled exception at 0x02c6ee05 in gltools_4.exe: 0xC0000005: Access violation reading location 0x10624dd3." when the program tries to run this :/

shaderManager.UseStockShader(GLT_SHADER_IDENTITY);

Also, this, because it might be important. http://i.imgur.com/VMFAT.png

Program code:

#include <GLTools.h>
#include <GLShaderManager.h>

#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endif

GLBatch triangleBatch;
GLShaderManager shaderManager;

void ChangeSize(int w, int h){
    glViewport(0, 0, w, h);
}

void setupRC(){
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);

    shaderManager.InitializeStockShaders();

    GLfloat vVerts[] = {-0.5f, 0.0f, 0.0f,
                        0.5f, 0.0f, 0.0f,
                        0.0f, 0.5f, 0.0f};
    triangleBatch.Begin(GL_TRIANGLES, 3);
    triangleBatch.CopyVertexData3f(vVerts);
    triangleBatch.End();
}

void RenderScene(void){
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    GLfloat vRed[] = {1.0f, 0.0f, 0.0f, 1.0f};
    shaderManager.UseStockShader(GLT_SHADER_IDENTITY);
    triangleBatch.Draw();

    glutSwapBuffers();
}


int main(int argc, char* argv[]){
    gltSetWorkingDirectory(argv[0]);

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Triangle");
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);

    GLenum err = glewInit();
    if(GLEW_OK != err){
        fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
        return 1;
    }

    setupRC();
    glutMainLoop();

    return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.