Archived

This topic is now archived and is closed to further replies.

bobbias

SDL problem...

Recommended Posts

Ok, i''m trying to use SDL in a BASIC program to pretty much initilize and close it. but I get this when I compile: 5 C:\Dev-Cpp\main.c ISO C++ forbids declaration of `SDL_main'' with no type I''m using Dev-C++ and i''ve decided to just include the headers all in the same directory as the source... Here''s my code (please only tell me what code will produce errors, and dont comment on my HORRABLE coding techniques...)
#include <stdlib.h>
#include "SDL.h"

main(int argc, char *argv[])
{
    if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        exit(1);
    }
    atexit(SDL_Quit);
    
    SDL_Event event;

    SDL_WaitEvent(&event);

    switch (event.type) {
        case SDL_KEYDOWN:
            printf("The %s key was pressed!\n",
                   SDL_GetKeyName(event.key.keysym.sym));
            break;
        case SDL_QUIT:
            exit(0);
    }
    
    
    return 0;
}
Yes, I suck at programming... (feel free to agree)

Share this post


Link to post
Share on other sites
Try including the return type for your main() function. i.e.:

int main(int argc, char *argv[])

Share this post


Link to post
Share on other sites
quote:
Original post by C-Junkie
int main

you forgot. not sure where its getting SDL_main, but I didn''t look long


SDL has a #define main SDL_main in its header. SDL itself defines the entry point in the library and calls whatever function you call main() in it''s entry point. When you see errors related to SDL_main, it usually means an error in the main() function you wrote.

Share this post


Link to post
Share on other sites
ok, now i've managed to only get 2 errors (link errors)


[Linker error] undefined reference to `mcount'

[Linker error] undefined reference to `WinMain@16'


[edited by - bobbias on March 17, 2004 6:19:19 PM]

Share this post


Link to post
Share on other sites
I''m not sure what that mcount reference is talking about, but the WinMain error is probably because you aren''t linking against SDLmain.lib. Try adding -lSDLmain to your linker options.

Share this post


Link to post
Share on other sites
I''ve added the following libraries in Dev-C++

SDL-1.2.7/lib/libSDL.a
SDL-1.2.7/lib/libSDL.dll.a
SDL-1.2.7/lib/libSDLmain.a

and those 2 errors are still there...

Share this post


Link to post
Share on other sites
Try -lmingw -lSDLmain -lSDL. -lmingw is required for WinMain, which is used in SDLmain. (This goes in the Project->Options; Parameters; Linker box). Also, make sure SDL-1.2.7/lib is in the linker directories.

Also, don't use both libSDL.dll.a and libSDL.a; they're the same, except that libSDL is a static library and libSDL.dll is a dynamic library. Use one or the other.

[edited by - ze_jackal on March 17, 2004 7:00:08 PM]

Share this post


Link to post
Share on other sites