SDL Graphics window tutorial not working

Hello I am a beginner in C++ and I am trying to learn some sdl.

Im doing this tutorial

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php

I am sure I typed the code correctly but I cant get it to compile, do I need extra compiler handles? If something was undefined how do i define it in C++ do I need to link to library via #include or something or is it a missing compiler handle, please help as I want to try and learn some correct code and get to the next step so i can write a game one day. Best wishes. Alistair.

cpp -w -lSDL2 -o sdlw2
sdlwindow2.cpp: In function ‘int main(int, char**)’:
sdlwindow2.cpp:26:10: error: ‘SDL’ was not declared in this scope
window = SDL CreateWindow( “SDL Tutorial”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN HEIGHT, SDL_WINDOW_SHOWN );
^
sdlwindow2.cpp:26:14: error: expected ‘;’ before ‘CreateWindow’
window = SDL CreateWindow( “SDL Tutorial”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN HEIGHT, SDL_WINDOW_SHOWN );

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

//Screen dimension constants

const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

int main( int argc, char* args[] )
{
//The window we’ll be rendering to
SDL_Window* window = NULL;

//The surface contained by the window
SDL_Surface* screenSurface = NULL;

//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( “SDL could not initialize! SDL_Error: %s\n”, SDL_GetError() );
}

else
{
//Create window
window = SDL CreateWindow( “SDL Tutorial”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN HEIGHT, SDL_WINDOW_SHOWN );
if ( window == NULL )
{
printf( “Window could not be created! SDL_ERROR: %s\n”, SDL_GetError() );
}
else
{
//Get window surface
screenSurface = SDL_GetWindowSurface( window );

//Fill the surface white
SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );

//Update the surface
SDL_UpdateWindowSurface( window );

//Wait two seconds
SDL_Delay( 2000 );
}

}

//Destroy window
SDL_DestroyWindow( window );

//Quit SDL subsystems
SDL_Quit();

return 0;

}

Try following the error message first of all. Deciphering error messages
is an important skill to develop. This one says that a keyword or
identifier “SDL” does not exist and points you to the line of code. Look
closely.

I would recommend you to not create global SDL variables like window or renderer. Instead, evey time you need it set is in a agrument of method/function like void Draw(SDL_Renderer* renderer) (you’ve got this, but in future tutorials he’s using global)

Im not into reading all the stuff you’ve pasted so I’ll write my own code

    int main(int argc,char *args[])
    {
        SDL_Init(SDL_INIT_EVERYTHING);
        SDL_Window* window = SDL_CreateWindow("NAME", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, SDL_WINDOW_SHOWN); // or 0 doesn't matter

        SDL_Surface* surface = NULL:

        bool quit = false;
        SDL_Event* event =  new SDL_Event;

        while(!quit && event->type != SDL_QUIT)
        {
            SDL_PollEvent(event);

            //do the surface stuff
        }

        //you can use this example of while loop too
        /*
          SDL_Event event;

        while(!quit)
        {
            while(SDL_PollEvent(&event)
            {
                if(event.type == SDL_QUIT)
                {
                    quit = true;
                }
            }
        
               //do the surface stuff
        }
        */

        SDL_FreeSurface(surface);
        delete event;
        SDL_DestroyWindow(window);
        SDL_Quit();
    }

For formatting code, use 3x tilde at the beginning of the code and 3x tilde at the end please.

@Shout Looks like you missed the allocation of event. Also, leaving a bare SDL_PollEvent can lead to situations where the event queue is not emptied before the frame ends. The commented section would be better.

about the event: I’d just put it on stack.

about the original problem: It’s just a typo like Jonny said, look closely to the row pointed by the error message.

I’m not sure copying a tutorial by typing manually is such a good idea. Just copy & paste something working and after it works you can start modifying and playing with things to learn.