Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL32.lib not linking properly [duplicate]

For some reason my OpenGL library file isn't linking correctly for Visual Studio 2013.

Here is all of my code:

#include <gl\glew.h>
#include <GL\GL.h>
#include <GL\GLU.h>
#include <GL\freeglut.h>

#include <iostream>
#include <cstdlib>

#pragma comment( lib, "OpenGL32.lib" )
#pragma comment( lib, "glu32.lib" )
#pragma comment( lib, "freeglut.lib" )

void init( void );
void display( void );

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

    glutDisplayFunc( display );

    glutMainLoop();

    return EXIT_SUCCESS;
}

void init( void ) { }

void display( void )
{
    glClear( GL_COLOR_BUFFER_BIT );

    return;
}

I compiled freeglut on my own system and I don't get any errors from the program if I remove anything specifically having to do with OpenGL32.lib. (i.e. if I remove the glClear() function, my program compiles and runs with no problems.) As soon as I add any GL commands though I start getting linking errors.

1>main.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl display(void)" (?display@@YAXXZ)

I've also tried taking out the #pragma directive and adding the OpenGL32.lib file into the additional dependencies for the linker and I've tried calling the #pragma directives before anything else in the program to no avail. I'm running a 64x Windows 8.1 box with an AMD Radeon 7700 HD series graphics card and brand new drivers for said card. Anyone got any ideas about what may be happening?

like image 546
wmaxlees Avatar asked Mar 06 '14 17:03

wmaxlees


1 Answers

The problem is that linker cannot find an opengl32.lib file. Try to find it under VC2013. Make sure that the path to it is included in additional library paths. If it is not there - add it. If you didn't find the library - install Windows SDK. The 64-bit version of opengl32.lib (ignore the 32 in the library, it doesn't mean anything) should be under %ProgramFiles%\Microsoft SDKs\Windows\\Lib\x64 directory. Add this path to lib paths of your project.

like image 54
D'artanian Avatar answered Oct 15 '22 00:10

D'artanian