Login | Register

Home > Forums > OpenGL > OpenGL Linker Errors Page :  1 
OpenGL Linker Errors

A few people have been sending e-mails asking how to get OpenGL applications to compile properly. Most receive a linker error such as LNK2019.

Please make sure that you have installed the Platform SDK along with your Visual Studio installation.

You will then see that the opengl32.lib is located in the lib directory of the platform SDK. For VS.NET 2003, this would most likely be : C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib

In your OpenGL program, make sure you also have the line :

#pragma comment(lib, "opengl32.lib")

Hope this helps.


I have re-installed platform SDK for VS.NET 2003 and I have included the pragma comment line. I still have the LNK2019 error.
Do you have any other suggestions? I am running a very bare bones application that is calling only one OpenGL command glClearColor. All of my other OpenGL programs will not currently compile without throwing this linker error.
Note too that I have also followed these instructions from

If you're using Visual C++ under Windows 9x, NT or 2K, your compiler comes with include files for OpenGL and GLU, as well as .lib files to link with. Otherwise download them from Microsoft

For GLUT, download these files. Install glut.h in your compiler's include directory, glut32.lib in your compiler's lib directory, and glut32.dll in your Windows system directory (c:\windows\system for Windows 9x, or c:\winnt\system32 for Windows NT/2000).

In summary, a fully installed Windows OpenGL development environment will look like this:

File Location
glu.h [compiler]\include\gl
glu32.lib [compiler]\lib
glu32.dll [system]

where [compiler] is your compiler directory (such as c:\Program Files\Microsoft Visual Studio\VC98) and [system] is your Windows 9x/NT/2000 system directory (such as c:\winnt\system32 or c:\windows\system).

If you're on a hardware platform that accelerates OpenGL, you'll need to install the latest OpenGL driver for your graphics card. This may have shipped with your hardware, or you can download it from your hardware vendor's Web page. Your 3D graphics card/platform vendor may also provide a replacement or addition for gl.h, which provides definitions and declarations for vendor-specific OpenGL extensions.

If you see files such as opengl.lib and glut.lib, these are SGI's unsupported libraries for Microsoft Windows. They should not be used. To use hardware acceleration, the Microsoft libraries are recommended. More info on the SGI libraries can be found here. Always link with either all Microsoft libraries (e.g., glu32.lib, glut32.lib, and opengl32.lib) or all SGI libraries (e.g., glu.lib, glut.lib, and opengl.lib). You can't use a combination of both Microsoft libarires and SGI libraries. However, you can install both sets of libraries on the same system. If you use SGI's .lib files, you'll need the corresponding .dll files installed in your system folder. (i.e., linking against opengl.lib requires that opengl.dll is installed at run time).

You'll need to instruct your compiler to link with the OpenGL, GLU, and GLUT libraries. In Visual C++ 6.0, you can accomplish this with the Project menu's Settings dialog box. Scroll to the Link tab. In the Object/library modules edit box, add glut32.lib, glu32.lib, and opengl32.lib to the end of any text that is present.

Which library is the linker complaining about.

Also make sure that Visual Studio is setup correctly. To do this, go to Tools > Options. Then click on Projects > VC++ Directories. Change the "Show directories for" dropdown box to "library files". Make sure that the lib directory of the platform SDK is in the list.

Here is the error:
Cube error LNK2019: unresolved external symbol _glClearColor referenced in function "public: void __thiscall CCubeView::DrawScene(void)" (?DrawScene@CCubeView@@QAEXXZ)
I have taken out all of the other opengl calls. I have gone into Tools | Options | VC++ | Directories ... then dropped down Library Files. The OpenGL32.lib file is in the Platform SDK directory. I have done a Dumpbin on OpenGL32.lib and ensured glClearColor is there. It is.
I am wondering if, somehow, the OpenGL32.dll is the problem ...? It is located in C:\Windows\System32\ .

The problem should not lie with the .dll as it is only used when executing the application.

Have you tried downloading a project from one of the tutorials to see if they compile?

I'll build the 06-PrimitiveAttributes project and get back to you.
I have completely removed OpenSceneGraph. I have completely re-installed Visual Studio.NET 2003. I have gone into My Computer | Properties and I have clicked on the Advanced Tab. I have then clicked on the Environmental Variables button. I have set the INCLUDE and LIB variables in both the system and user sections to the PlatformSDK and FrameworkSDK.
I try and build and unaltered version of 06-Primative Attributes and I still get a slew of LNK2019 errors.
Eureka!!! Visual Studio.NET 2003's output window was showing that the .h files were being read from a different directory other than the PlatformSDK directory. I removed these files, and away she goes. So, in short, the wrong header files were being read.

I'm glad you found the problem :)


Home > Forums > OpenGL > OpenGL Linker Errors Page :  1 

You need to be logged in to reply to this topic.

All Rights Reserved, © Zeus Communications, Multimedia & Development 2004-2005

Read the Disclaimer