-1

I am new to OpenGL and I'm now trying examples in the book, I've included all the libraries correctly, but it seems there are still something not going right.

Two libraries: freeglut_static.lib gltools.lib were included in the project.

This is the code:

// Triangle.cpp
// Our first OpenGL program that will just draw a triangle on the screen.
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS X version of GLUT
#else
#define FREEGLUT_STATIC
#include <GL/glut.h> // Windows FreeGlut equivalent
#endif
GLBatch triangleBatch;
GLShaderManager shaderManager;
///////////////////////////////////////////////////////////////////////////////
// Window has changed size, or has just been created. In either case, we need
// to use the window dimensions to set the viewport and the projection matrix.
void ChangeSize(int w, int h)
{
    glViewport(0, 0, w, h);
}
///////////////////////////////////////////////////////////////////////////////
// This function does any needed initialization on the rendering context.
// This is the first opportunity to do any OpenGL related tasks.
void SetupRC()
{
    // Blue background
    glClearColor(0.0f, 0.0f, 1.0f, 1.0f );
    shaderManager.InitializeStockShaders();
    // Load up a triangle
    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();
}
///////////////////////////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
    // Clear the window with current clearing color
    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, vRed);
    triangleBatch.Draw();
    // Perform the buffer swap to display the back buffer
    glutSwapBuffers();
}

///////////////////////////////////////////////////////////////////////////////
// Main entry point for GLUT based programs
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;
}

Error messsages given :

 1>Linking...
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>Triangle.obj : error LNK2019: unresolved external symbol _glewGetErrorString@4 referenced in function _main
1>Triangle.obj : error LNK2019: unresolved external symbol _glewInit@0 referenced in function _main
1>D:\XING BIZHOU\project\openglproj\Debug\openglproj.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://d:\XING BIZHOU\project\openglproj\openglproj\Debug\BuildLog.htm"
1>openglproj - 3 error(s), 2 warning(s)
k0ala Xing
  • 55
  • 7
  • 1
    `_glewGetErrorString` - you need to [add `glew32.lib`](http://stackoverflow.com/q/17370/1888983). Also some good results on [google](https://www.google.com.au/search?q=error+LNK2019%3A+unresolved+external+symbol+_glewGetErrorString%404+referenced+in+function&oq=error+LNK2019%3A+unresolved+external+symbol+_glewGetErrorString%404+referenced+in+function&aqs=chrome..69i57.287j0j7&sourceid=chrome&es_sm=93&ie=UTF-8). – jozxyqk Jul 20 '15 at 08:47
  • I have added the glew32.lib in the project, but still the same error? – k0ala Xing Jul 20 '15 at 09:25
  • I understand why, its because I didn't use the library recommended from the book, so it was the version problem, thank you all – k0ala Xing Jul 20 '15 at 13:26

2 Answers2

1
unresolved external symbol _glewGetErrorString

This means the compiler is not finding the glew32 library in your environment. Try installing it and making sure it is in your LDPATH so that your compiler can see it.

Dani Torramilans
  • 340
  • 1
  • 2
  • 7
  • Where can I find LDPATH? – k0ala Xing Jul 20 '15 at 09:29
  • It is an _environment variable_. There are several: `LD_LIBRARY_PATH`, `LIBRARY_PATH` and `PATH`. Anyway if you install `libglew-dev` from the ubuntu repositories (`sudo apt-get install libglew-dev`) it should already be in your library path. – Dani Torramilans Jul 20 '15 at 09:40
  • I'm using Visual studio 2008 and I added these libraries manually – k0ala Xing Jul 20 '15 at 09:44
  • 1
    Oh. Then just input your library to Visual Studio. As @Aaron said in his answer, Project/Properties/Linker/Input/Additional Dependencies is the place to do this. – Dani Torramilans Jul 20 '15 at 09:46
  • 1
    I understand why, its because I didn't use the library recommended from the book, so it was the version problem, thank you all – k0ala Xing Jul 20 '15 at 13:26
0

Have you input your library? In Project/Properties/Linker/Input/Additional Dependencies

Aaron
  • 139
  • 1
  • 7