SDL 1.2.8/OpenGL/Dev-C++: undefined reference to `SDL_SetModuleHandle'

Dear people,
I wanted to write a little program for testing SDL/OpenGL (SDL-Version 1.2.8)
with Dev-C++.

My Code:

#include
#include

#include “SDL.h”
#include “SDL_opengl.h”

void RefreshScreen()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

/* We don't want to modify the projection matrix. */
glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );

/*glBegin(GL_QUADS);
    glColor3ub(255, 0, 0);        glVertex2f(0, 0.5);
    glColor3ub(0, 255, 0);        glVertex2f(0.5, 0.5);
    glColor3ub(0, 0, 255);        glVertex2f(0.5, 1.0);
    glColor3ub(255, 255, 0);    glVertex2f(0, 1.0);
glEnd();*/

glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0

glBegin(GL_TRIANGLES); // Drawing Using Triangles

glColor3ub(255, 0, 0); 
glVertex3f( 0.0f, 1.0f, 0.0f); // Top
glColor3ub(0, 255, 0);
glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
glColor3ub(0, 0, 255);
glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right

glEnd(); // Finished Drawing The Triangle

}

int main(int argc, char **argv)
{
SDL_Surface *screen;
int running;

// Clean up on exit
atexit(SDL_Quit);

// Initialize the SDL library
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    fprintf(stderr,
            "Couldn't initialize SDL: %s\n", SDL_GetError());
    exit(-1);
}

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
if (!screen) {
    fprintf(stderr, "Konnte Bildschirmmodus nicht setzen: %s\n",
        SDL_GetError());
    exit(1);
}

glViewport(0, 0, screen->w, screen->h);

glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f,((GLfloat) screen->w) / 
((GLfloat) (screen->h==0?1:screen->h)),0.1f,100.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glShadeModel(GL_SMOOTH); // Enables Smooth Shading

glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background

glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice

Perspective Calculations

running = 1;

while(running) {
    SDL_Event event;

    while(SDL_PollEvent(&event)) {
        switch(event.type) {
        case SDL_KEYDOWN:
            running = 0;
            break;
        case SDL_QUIT:
            running = 0;
            break;
        }
    }

    RefreshScreen();

    SDL_GL_SwapBuffers();
}

return 0;

}

My linker options are: -lmingw32 -lSDL -lSDLmain -lopengl32 -lglu32
It should compile, but it doesn’t. There comes the error message:
[Linker error] undefined reference to `SDL_SetModuleHandle’

I have no idea how to solve that problem.

So I cry for help :wink: .

For your additional information:
when I add the hack:
#if defined(_WIN32) && defined(MINGW32)
#undef main
#endif

that I found somewhere in the internet, after including the header files it
compiles properly. But I don’t know which real consequences this evil hack can
have, so please give me a proper solution to my problem.

Thanks in advance
Wolfgang

Dear people,
I wanted to write a little program for testing SDL/OpenGL (SDL-Version 1.2.8)
with Dev-C++.

My Code:

My linker options are: -lmingw32 -lSDL -lSDLmain -lopengl32 -lglu32
It should compile, but it doesn’t. There comes the error message:
[Linker error] undefined reference to `SDL_SetModuleHandle’

I have no idea how to solve that problem.

So I cry for help :wink: .

The order appears to matter. I get the same error as you, but if I swap
the order of SDL and SDLmain it works:

-lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32

Use the following to get suitable flags for your platform:

sdl-config --cflags
sdl-config --libs

On my box I get:
-I/usr/local/include/SDL -Dmain=SDL_main
and
-L/usr/local/lib -lmingw32 -lSDLmain -lSDL -mwindows

Note that the order is correct. Try and use these results in your
Makefile directly with something like this:

SDL_LIBS=$(shell sdl-config --libs)
SDL_CFLAGS=$(shell sdl-config --cflags)

For your additional information:
when I add the hack:
#if defined(_WIN32) && defined(MINGW32)
#undef main
#endif

The -Dmain=SDL_main from above is supposed to remove the need for this
kind of thing,

cheers,
John.On Tue, Aug 16, 2005 at 08:52:40AM +0000, Wolfgang Keller wrote:

that I found somewhere in the internet, after including the header files it
compiles properly. But I don’t know which real consequences this evil hack can
have, so please give me a proper solution to my problem.

Thanks in advance
Wolfgang


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl