Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

So I'm trying to write a simple application with SDL 1.2 and OpenGL. This a stripped down version of the code containing the one problem I'm having.

//The headers
#include "SDL.h"
#include "SDL_opengl.h"

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//Event handler
SDL_Event event;

bool initGL()
    //Initialize Projection Matrix
    glMatrixMode( GL_PROJECTION );

    //Initialize Modelview Matrix
    glMatrixMode( GL_MODELVIEW );

    //Initialize clear color
    glClearColor( 0.f, 0.f, 0.f, 1.f );

    //Check for error
    GLenum error = glGetError();
    if( error != GL_NO_ERROR )
        printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) );
        return false;

    return true;

bool init()
    //Initialize SDL
    if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
        return false;

    //Create Window
        return false;

    //Enable unicode

    //Initialize OpenGL
    if( initGL() == false )
        return false;

    //Set caption
    SDL_WM_SetCaption( "OpenGL Test", NULL );

    return true;

void render()
    //Clear color buffer
    glClear( GL_COLOR_BUFFER_BIT );

    glBegin( GL_QUADS );
        glVertex2f( -0.5f, -0.5f );
        glVertex2f(  0.5f, -0.5f );
        glVertex2f(  0.5f,  0.5f );
        glVertex2f( -0.5f,  0.5f );

    //Update screen

void clean_up()
    //Quit SDL

int main( int argc, char *argv[] )
    //Quit flag
    bool quit = false;

    if( init() == false )
        return 1;

    //Wait for user exit
    while( quit == false )
        //While there are events to handle
        while( SDL_PollEvent( &event ) )
            if( event.type == SDL_QUIT )
                quit = true;
            else if( event.type == SDL_KEYDOWN )
                //Handle keypress with current mouse position
                int x = 0, y = 0;
                SDL_GetMouseState( &x, &y );

        //Render frame

    //Clean up

    return 0;

Anyway the code has a problem with gluErrorString() and reports:

1>main.obj : error LNK2019: unresolved external symbol _gluErrorString@4 referenced in function "bool __cdecl initGL(void)" (?initGL@@YA_NXZ)

1>C:\...\Debug\sdl1.exe : fatal error LNK1120: 1 unresolved externals

I'm using Visual Studio C++ 2010 Express. I'm using SDL 1.2.15 and freeglut. I've added to the VC++ Directories both the SDL and freeglut library and include directories respectively and in the Linker general dependencies have added SDL.lib, SDLmain.lib, OpenGL32.lib, and freeglut.lib. And SDL.dll and freeglut.dll are included with the executable.

What's really baffling me is I can run SDL code with this same set up as well as OpenGL (if I include gl/glu.h and gl/gl.h manually), but trying to run them together has brought me to a screeching halt. If I comment out the line printf( "Error initializing OpenGL! %s\n", gluErrorString( error ) ); it works fine, but I have no idea why it can't seem to work with a simple thing like gluErrorString(), especially because gluErrorString() works fine in my OpenGL only code.

From what I understand #include "SDL_opengl.h" is supposed to include the opengl headers for me, and it seems to work for all but this one line, which I don't understand. If there's any further pertinent information needed I will provide it. Any help is greatly appreciated.

share|improve this question
Since this question is primarily about coding that's not specific to gamedev, I've voted to close it as off topic. Questions that are not specific to game dev should be asked at stackoverflow.com. –  Byte56 Jun 23 '13 at 17:05
add comment

closed as off-topic by Sean Middleditch, bummzack, Byte56, Seth Battin, Anko Jun 29 '13 at 19:18

This question appears to be off-topic. The users who voted to close gave these specific reasons:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Seth Battin, Anko
  • "This question does not appear to be about game development within the scope defined in the help center." – Sean Middleditch, bummzack, Byte56
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 2 down vote accepted

Headers provide (among other things) function declarations and type definitions into the source files which you include them. Libraries you link provide the symbols representing the definitions for those function declarations.

If you're missing an include, you're going to get a compiler error about an unknown identifier, type or function.

If you're missing a library or forgot to define a function you declared yourself, you're going to get a linker error about a missing symbol.

As your error is about a missing symbol for gluErrorString, you need to link glu32.lib, which is the OpenGL utility library.

For almost anything provided by a Microsoft-supplied library, you can find out which header to include and what library to link by reading the MSDN page for the function.

share|improve this answer
Understood. I was able to fix the problem. Thanks for your help. –  James P Jun 23 '13 at 5:38
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.