Naor Hadar
Naor Hadar

Reputation: 577

Cant compile any opengl/freeglut/glut source code

I have this code which i took from an opengl example code:

#include <GL/glut.h>

// Display callback ------------------------------------------------------------

void display()
{
    // clear the draw buffer .
    glClear(GL_COLOR_BUFFER_BIT);   // Erase everything

    // set the color to use in draw
    glColor3f(0.5, 0.5, 0.0);       
    // create a polygon ( define the vertexs) 
    glBegin(GL_POLYGON); {           
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5,  0.5);
        glVertex2f( 0.5,  0.5);
        glVertex2f( 0.5, -0.5);
    } glEnd();

    // flush the drawing to screen . 
    glFlush(); 
}

// Keyboard callback function ( called on keyboard event handling )
void keyboard(unsigned char key, int x, int y)
{
    if (key == 'q' || key == 'Q')
        exit(EXIT_SUCCESS);
}

// Main execution  function 
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);      // Initialize GLUT
    glutCreateWindow("OpenGL example");  // Create a window
    glutDisplayFunc(display);   // Register display callback
    glutKeyboardFunc(keyboard); // Register keyboard callback
    glutMainLoop();             // Enter main event loop

    return (EXIT_SUCCESS);
} 

it should work right? but when i run it:

Error   1   error LNK2019: unresolved external symbol __imp__glutMainLoop@0 referenced in function _main    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   2   error LNK2019: unresolved external symbol __imp__glutKeyboardFunc@4 referenced in function _main    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   3   error LNK2019: unresolved external symbol __imp__glutDisplayFunc@4 referenced in function _main C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   4   error LNK2019: unresolved external symbol __imp____glutInitWithExit@12 referenced in function _glutInit_ATEXIT_HACK@8   C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   5   error LNK2019: unresolved external symbol __imp____glutCreateWindowWithExit@8 referenced in function _glutCreateWindow_ATEXIT_HACK@4    C:\Users\Naor\documents\visual studio 2012\Projects\test\test\Source.obj    test
Error   6   error LNK1120: 5 unresolved externals   C:\Users\Naor\documents\visual studio 2012\Projects\test\Debug\test.exe 1   1   test

I installed opengl, freeglut correctly (i mean, it runs and vc++ find's it no problem), but i cant run any source code i find.. (same error's)

Upvotes: 1

Views: 971

Answers (1)

Naor Hadar
Naor Hadar

Reputation: 577

Found the answer, to anyone who have this kind of issue check these:

  1. You linked your lib and include correctly. (32bit is recommended, fixed my error).
  2. After you've done this, you'll probably get an error that it cant open or find some dll file.
  3. Check what dll it is (in the error message), copy it where your exe is located (for debug mode to the Debug folder, and release to the Release folder).

Hope that fixed your error :)

Upvotes: 2

Related Questions