Help with SDL installation/compiling for Computer Science 481/681 class

Hi,
I am having horrible problems compiling SDL programs in MinGW
3.1.0-1, MSYS-1.0.11, gcc-core-3.4.1, and SDL 1.2.7. Here is how I am
compiling it with the code below. (also, I have left the header as
pointed out in the book Linux Game Programming <SDL/SDL.h> to <SDL.h>
or “SDL.h”).

$ gcc -o blitting_surfaces_sdl.exe blitting_surfaces_sdl.c
-I"C:/mingw/include/SDL-1.2.7"
blitting_surfaces_sdl.c: In function `SDL_main’:
blitting_surfaces_sdl.c:6: error: number of arguments doesn’t match prototype
/mingw/include/SDL_main.h:54: error: prototype declaration

#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Rect src, dest;

// Init SDL’s video system and check for errors
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}

// Make sure SDL_Quit gets called when the program exits! d
atexit(SDL_Quit);

screen = SDL_SetVideoMode(256, 256, 16, 0);
if(screen == NULL)
{
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}

image = SDL_LoadBMP(“test-image.bmp”);
if(image == NULL)
{
printf(“Unable to load bitmap.\n”);
return 1;
}

src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;

dest.x = 0;
dest.y = 0;
dest.w = image->w;
dest.h = image->h;

SDL_BlitSurface(image, &src, screen, &dest);

SDL_UpdateRect(screen, 0, 0, 0, 0);

SDL_Delay(10000);

SDL_FreeSurface(image);

return 0;
}

Thanks!

Dexter F. Stowers

For MinGW the main entry usually needs to be defined like this:

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

instead of

int main()

even if you don’t pass in any arguments. Also you might want to compile
with this command

gcc -o blitting_surfaces_sdl.exe blitting_surfaces_sdl.c sdl-config --cflags --libs

which will use the sdl-config script to automagically append the flags
and libs needed to compile SDL programs.

brian

Dexter Stowers wrote:>Hi,

I am having horrible problems compiling SDL programs in MinGW

3.1.0-1, MSYS-1.0.11, gcc-core-3.4.1, and SDL 1.2.7. Here is how I am
compiling it with the code below. (also, I have left the header as
pointed out in the book Linux Game Programming <SDL/SDL.h> to <SDL.h>
or “SDL.h”).

$ gcc -o blitting_surfaces_sdl.exe blitting_surfaces_sdl.c
-I"C:/mingw/include/SDL-1.2.7"
blitting_surfaces_sdl.c: In function `SDL_main’:
blitting_surfaces_sdl.c:6: error: number of arguments doesn’t match prototype
/mingw/include/SDL_main.h:54: error: prototype declaration

#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Rect src, dest;

// Init SDL’s video system and check for errors
if (SDL_Init(SDL_INIT_VIDEO) != 0)
{
printf(“Unable to initialize SDL: %s\n”, SDL_GetError());
return 1;
}

// Make sure SDL_Quit gets called when the program exits! d
atexit(SDL_Quit);

screen = SDL_SetVideoMode(256, 256, 16, 0);
if(screen == NULL)
{
printf(“Unable to set video mode: %s\n”, SDL_GetError());
return 1;
}

image = SDL_LoadBMP(“test-image.bmp”);
if(image == NULL)
{
printf(“Unable to load bitmap.\n”);
return 1;
}

src.x = 0;
src.y = 0;
src.w = image->w;
src.h = image->h;

dest.x = 0;
dest.y = 0;
dest.w = image->w;
dest.h = image->h;

SDL_BlitSurface(image, &src, screen, &dest);

SDL_UpdateRect(screen, 0, 0, 0, 0);

SDL_Delay(10000);

SDL_FreeSurface(image);

return 0;
}

Thanks!

Dexter F. Stowers


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