1

I have trouble with debugging OpenGL code in Visual Studio 2012

Error   3   error LNK1120: 1 unresolved externals

Error   2   error LNK2019: unresolved external symbol _LoadShaders referenced in function "void __cdecl init(void)" (?init@@YAXXZ)  C:\Users\New User\Documents\OpenGl\Lesson1_1test\Lesson1_1test\triangles.obj    Lesson1_1test

here is my code and it from book called OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3 (8th Edition)

//
//
// triangles.cpp
//
//

#include <iostream>
using namespace std;

#include "vgl.h"
#include "LoadShaders.h"

enum VAO_IDs {Triangles, NumVAOs};
enum Buffer_IDs {ArrayBuffer, NumBuffers};
enum Attrib_IDs { vPosition = 0};

GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];

const GLuint NumVertices = 6;

//--init

void 
init(void)
{
    glGenVertexArrays(NumVAOs, VAOs);
    glBindVertexArray(VAOs[Triangles]);

    GLfloat vertices[NumVertices][2] = {
        {-0.90, -0.90},
        {0.85, -0.90},
        {-0.90, 0.85},
        {0.90, -0.85},
        {0.90, 0.90},
        {-8.50, 0.90}
    };

    glGenBuffers(NumBuffers, Buffers);
    glBindBuffer(GL_ARRAY_BUFFER, Buffers[ArrayBuffer]);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    ShaderInfo shaders[] = {{GL_VERTEX_SHADER, "triangles.vert"}, { GL_FRAGMENT_SHADER, "triangles.frag"},{ GL_NONE, NULL}};

    GLuint program = LoadShaders(shaders);
    glUseProgram(program);

    glVertexAttribPointer(vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));

    glEnableVertexAttribArray(vPosition);
}

//Display

void 
display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    glBindVertexArray(VAOs[Triangles]);

    glDrawArrays(GL_TRIANGLES, 0, NumVertices);

    glFlush();
}


//main

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA);
    glutInitWindowPosition(512,512);
    glutInitContextVersion(4,3);
    glutInitContextProfile(GLUT_CORE_PROFILE);
    glutCreateWindow(argv[0]);

    if(glewInit()) {
        cerr << "Unable to initialize GLEW ... exiting " << endl;
        exit(EXIT_FAILURE);
    }

    init();

    glutDisplayFunc(display);

    glutMainLoop();
}
genpfault
  • 51,148
  • 11
  • 85
  • 139
DM_KAZ
  • 13
  • 2
  • Check this SO link "error LNK2019: unresolved external symbol _LoadShaders..."- http://stackoverflow.com/questions/16886087/error-lnk2019-unresolved-external-symbol-loadshaders-referenced-in-function-v – SChepurin Dec 17 '13 at 09:01
  • 1
    Possible duplicate? http://stackoverflow.com/questions/16886087/error-lnk2019-unresolved-external-symbol-loadshaders-referenced-in-function-v – Hariprasad Dec 17 '13 at 09:01
  • 1
    have you added those files to your project? "loadshaders" and "vgl" – Anton D Dec 17 '13 at 09:02
  • yes i already added "loadshaders" and "vgl" too compile is not issue but debugging is error. – DM_KAZ Dec 17 '13 at 09:14

2 Answers2

0

You need to add some lib file to the linker. It is probably in some project setup dialog.

user877329
  • 6,717
  • 8
  • 46
  • 88
0

You need to ensure that the opengl directories are added to your lookup path directories. In VS2010 the dialog looks like this: Add directories to lookup paths

In VS2012 the dialog looks like this: Add directories to lookup paths

In both you can get to them by going to project properties >> VC++ Directories

Add locations based on the following:

  • Bin directory (contains dll files for example) add to executable directories
  • include directory (containing .h files) add to include directories
  • library directory (containing .lib files) add to library directories
  • source directory (containing .cpp files) add to source directories

reference and exclude directories you can leave alone unless you have an explicit need to alter them.

Hope this helps, but let me know if you need more info!:)

vallentin
  • 23,478
  • 6
  • 59
  • 81
GMasucci
  • 2,834
  • 22
  • 42
  • yeah thank you for quality detail explain however...i just realize this book might not for window......coz of i can't find .dll or .lib for window os. that is biggest problem is I have not .dll or file file. or i rather it is problem from Visual Studio 2012? I only see freeglut_static.lib, freeglut_static.lib and freeglut_vs2010s.lib etc Now I will trying visual studio 2010 now. – DM_KAZ Dec 17 '13 at 10:12
  • you might not need to set all the paths, just the ones you need, so if you are using static libraries (.lib files) you may not need a dll path :) – GMasucci Dec 17 '13 at 10:16