SDL: Linkers and Libraries

Started by
28 comments, last by orcfan32 18 years, 8 months ago
Yes, I have it in the same directory and here's the first section:

C:\libraries\SDL-1.2.8\lib\libSDL.a(SDL_systimer.o)(.text+0x15) In function `SDL_StartTicks':
[Linker error] undefined reference to `timeBeginPeriod@4'
[Linker error] undefined reference to `timeGetTime@0'
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Advertisement
Okay...can you show the code?

It looks like a timer problem...did you initialise the timer subsystem?

if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) < 0){        std::cerr << "ERROR: <" << SDL_GetError() << ">" << std::endl;        return false;}
Gary.Goodbye, and thanks for all the fish.
Here:

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <SDL/SDL.h>#include <windows.h>/* PLEASE NOTE: the program will require SDL.dll which is located in              dev-c++'s dll directory. You have to copy it to you			  program's home directory or the path. *//* The screen surface */SDL_Surface *screen = NULL;/* This function draws to the screen; replace this with your own code! */static voiddraw (){    static int direction = 0;    static int value = 0;    static int which = 0;    SDL_Rect rect;    Uint32 color;    /* Create a black background */    color = SDL_MapRGB (screen->format, 0, 0, 0);    SDL_FillRect (screen, NULL, color);    /* Determine which color the layer should have */    if (direction == 0)    {        value += 2;        if (value >= 256)        {            value = 255;            direction = 1;        }    }    else    {        value -= 2;        if (value <= 5)        {            value = 0;            direction = 0;            which++;            if (which == 5)                which = 0;        }    }    /* Draw a layer with variable color */    switch (which)    {      case 0:          color = SDL_MapRGB (screen->format, value, 0, 0);          break;      case 1:          color = SDL_MapRGB (screen->format, 0, value, 0);          break;      case 2:          color = SDL_MapRGB (screen->format, 0, 0, value);          break;      case 3:          color = SDL_MapRGB (screen->format, value, value, value);          break;      case 4:          color = SDL_MapRGB (screen->format, value, 0, value);          break;    }    rect.w = screen->w / 2;    rect.h = screen->h / 2;    rect.x = (screen->w / 2) - (rect.w / 2);    rect.y = (screen->h / 2) - (rect.h / 2);    SDL_FillRect (screen, &rect, color);    /* Make sure everything is displayed on screen */    SDL_Flip (screen);    /* Don't run too fast */    SDL_Delay (1);}intmain (int argc, char *argv[]){    char *msg;    int done;    /* Initialize SDL */    if (SDL_Init (SDL_INIT_VIDEO) < 0)    {        sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());        MessageBox (0, msg, "Error", MB_ICONHAND);         free (msg);        exit (1);    }    atexit (SDL_Quit);    /* Set 640x480 16-bits video mode */    screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);    if (screen == NULL)    {        sprintf (msg, "Couldn't set 640x480x16 video mode: %s\n",          SDL_GetError ());        MessageBox (0, msg, "Error", MB_ICONHAND);         free (msg);        exit (2);    }    SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);    done = 0;    while (!done)    {        SDL_Event event;        /* Check for events */        while (SDL_PollEvent (&event))        {            switch (event.type)            {            case SDL_KEYDOWN:                break;            case SDL_QUIT:                done = 1;                break;            default:                break;            }        }        /* Draw to screen */        draw ();    }    return 0;}


Specs: Windows XP, Dev-C++
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
The code isn't the problem, here. Now it's a case of the correct libraries not being linked. Not being over familiar with Dev-C++ (to the point of having uninstalled it a while back), I'm not sure why -- but it appears that the core windows and standard libraries may not be getting linked like they should. For a command line compile, this is done simply by adding the switch "-mwindows". Perhaps you could dig around and see if something like that got disabled or deleted.

EDIT (now that I thought of it): If nothing else, you could delete your Dev-C++ project file(s) (not your source, just the project file that Dev-C++ created), reinstall Dev-C++, and create a new Win32 project and add your source files in again (along with the linked libraries -lsdl and -lsdlmain). A long fix, I know, but worth a try if you can't figure it out.
{[JohnE, Chief Architect and Senior Programmer, Twilight Dragon Media{[+++{GCC/MinGW}+++{Code::Blocks IDE}+++{wxWidgets Cross-Platform Native UI Framework}+++
Try:

if (SDL_Init (SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0){    sprintf (msg, "Couldn't initialize SDL: %s\n", SDL_GetError ());    MessageBox (0, msg, "Error", MB_ICONHAND);     free (msg);    exit (1);}
Gary.Goodbye, and thanks for all the fish.
I must say I tend to agree...if you've explicity included all libraries (via the browse type option), I am wondering if you have the project as a WIN32 gui project and it should be a WIN32 console project?

I know that the SDL projects I've done in the past with dev-c++ have been win32 console projects.

Straws and grasping at springs to mind though.

Sorry, not being much help to you.
Gary.Goodbye, and thanks for all the fish.
If it helps, here's the SDL linker flags I use within Dev C++.


-lmingw32 -lSDLmain -lSDL -lSDL_ttf -lSDL_mixer -lglu32 -lopengl32



You may not need anything from beyond -lSDL for now, though.
Okay.

As a test I created 1 win32 console app and compiled and ran the code fine, and another win32 windows application which also ran okay.

Both with Dev-c++ 4.9.9.2.

The only other suggestion I have is that you download and install the sdl dev-c++ devpack again???
Gary.Goodbye, and thanks for all the fish.
Ok, think that I'm on the brink of it working!

All thats left is there's a syntax error in SDL_audio.h. The line of code is:

void (SDLCALL *filters[10]) (struct SDL_AudioCVT *cvt, Uint16 format);

With a syntax error before the [ token. Any suggestions? I've tried shifting around the code some, but I really don't want to mess up this header file..
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit
Some help here..?
The best thing to do is just choose whatever you think you'd prefer, and go for it. -Promit

This topic is closed to new replies.

Advertisement