0

I keep getting an error when compiling an SDL program I'm working on.

I get the "'screen' was not declared in this scope" error, even though I'm pretty sure it's declared in 'globals.h'.

globals.h

#ifndef GLOBALS_H_INCLUDED
#define GLOBALS_H_INCLUDED
#include "gui.h"
#include "player.h"
#include "SDL.h"
#include "timer.h"
#include <stdlib.h>
#include <string>

SDL_Surface* screen = NULL;
SDL_Event event;
bool done;
int screenW = 640, screenH = 480

#endif

setup.h

#ifndef SETUP_H_INCLUDED
#define SETUP_H_INCLUDED
#include "globals.h"
#include "SDL.h"
#include "SDL_ttf.h"
#include <windows.h>

int createWindow()
{
    SDL_Init( SDL_INIT_EVERYTHING );
    TTF_Init();

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

    SDL_WM_SetCaption( "Thing", NULL );

    screen = SDL_SetVideoMode(screenW, screenH, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_HWACCEL/*|SDL_RESIZABLE*/);
    if(!screen)
    {
        printf("Unable to set %ix%i video: %s\n", screenW, screenH, SDL_GetError());
        return 1;
    }

    return 0;
}

#endif

I get the error in the createWindow() function. It also says 'screenW' and 'screenH' aren't declared. Why is this? global.h is included and it worked all the time up until now.

Edited by pilly

2
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by _avishek
0

This forum is really helpful...

Edited by pilly

0

I think you need to prepend the keyword "extern" in line 10 of globals.h like so:

extern SDL_Surface* screen = NULL;

I also think that you need to prepend "extern" before the declaration of all the other global variables in globals.h.

Edited by _avishek

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.