I copied the following from a back but I'm getting the erros that you see at the bottom of the page.

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

int main()
{
    int main()

        SDL_Surface *screen;

        if(SDL_Init(SDL_INIT_VIDEO) != 0)
        {
            printf("Unable to initialize SDL: %s\n", SDL_GetError());
            return 1;
        }

        atexit(SDL_Quit);

        screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);

        if(screen == NULL)
        {
            printf("Unable to set video mode: %s\n", SDL_GetError());
            return 1;
        }

        printf("Success!\n");

        return 0;
}

Compile line -> gcc initializing-sdl.c -o sdltest \sdl-config --cflags --libs``

Errors

initializing-sdl.c: In function ‘main’:
initializing-sdl.c:11:9: error: expected declaration specifiers before ‘if’
         if(SDL_Init(SDL_INIT_VIDEO) != 0)
         ^
initializing-sdl.c:17:9: error: expected declaration specifiers before ‘atexit’
         atexit(SDL_Quit);
         ^
initializing-sdl.c:19:9: error: expected declaration specifiers before ‘screen’
         screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
         ^
initializing-sdl.c:21:9: error: expected declaration specifiers before ‘if’
         if(screen == NULL)
         ^
initializing-sdl.c:27:9: error: expected declaration specifiers before ‘printf’
         printf("Success!\n");
         ^
initializing-sdl.c:29:9: error: expected declaration specifiers before ‘return’
         return 0;
         ^
initializing-sdl.c:30:1: error: expected declaration specifiers before ‘}’ token
 }
 ^
initializing-sdl.c:9:22: error: declaration for parameter ‘screen’ but no such parameter
         SDL_Surface *screen;
                      ^
initializing-sdl.c:30:1: error: expected ‘{’ at end of input
 }
 ^
initializing-sdl.c: In function ‘main’:
initializing-sdl.c:30:1: error: expected declaration or statement at end of input

Again, I got this from my book.

You've got int main() twice.

Fixed that now here's what I'm getting.

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

int main()
{
    SDL_Surface *screen;

    if(SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    atexit(SDL_Quit);

    screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);

    if(screen == NULL)
    {
        printf("Unable to set video mode: %s\n", SDL_GetError());
        return 1;
    }

    printf("Success!\n");

    return 0;
}





initializing-sdl.c: In function ‘main’:
initializing-sdl.c:17:12: warning: assignment makes pointer from integer without a cast [enabled by default]
     screen = SDL_Set_VideoMode(640, 480, 16, SDL_FULLSCREEN);
            ^
/tmp/ccSsAPkP.o: In function `main':
initializing-sdl.c:(.text+0x58): undefined reference to `SDL_Set_VideoMode'
collect2: error: ld returned 1 exit status

undefined reference to SDL_Set_VideoMode

You're not linking against the library containing this function. This is probably because the function no longer exists (as of SDL version 2) other than as some kind of stub.

You'll have to either get an old version of SDL, or update your code.

I changed SDL_Set_VideoMode to SDL_SetVideoMode and it almost worked. All it did was give me screen terrible resolution and a few errors on the command line as the program ran.

8d3acca065d54f6b1a2b6002566565f0

This post has no text-based content.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.