   undefined reference to game_loop'
  Hello,I am having trouble with my game_loop variable.  It controls the game loop and determines when to end.  I am not sure where to define and initialize it so I can use it from any file.  Here is my code:main.cpp//SDL template#include <iostream>#include <SDL/SDL.h>#include "display.h"#include "event.h"#include "layout.h"using namespace std;int main(int argc, char* args[]){//static int game_loop;//loop unti game_loop = truegame_loop = 0;//initialize SDLSDL_init();//star game loopif(!game_loop){//get keyboard/mouse event to quitevent_update();}//free surfaces and exit SDLSDL_exit();return 0;}event.cpp//handle events#include "event.h"#include <SDL/SDL.h>#include "layout.h"SDL_Event event;void event_update(){while(SDL_PollEvent(&event)){if(event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE){game_loop = 1;}}}display.cpp#include "display.h"#include "layout.h"#include <SDL/SDL.h>#include <stdexcept>using namespace std;SDL_Surface *screen;void SDL_init()//initialize SDL{if(SDL_Init(SDL_INIT_VIDEO) == -1){throw runtime_error("Cannot init video.");}screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE);if(!screen){throw runtime_error("Cannot set SDL video mode");}SDL_WM_SetCaption("SDL-Template", "SDL-Template");}void SDL_exit()//free surfaces and quit SDL{SDL_Quit();//quit SDL}layout.h#ifndef LAYOUT_H#define LAYOUT_H//set dimensions of screen and the bits per pixelconst int SCREEN_WIDTH = 800;const int SCREEN_HEIGHT = 600;const int SCREEN_BPP = 32;extern int game_loop;#endifI didn't post event.h or display.h since I didn't think it was relevent.Here are the errors:g++ -O2 -Wall -Werror -ansi   -c -o main.o main.cppg++ -O2 -Wall -Werror -ansi   -c -o event.o event.cppg++ -o SDL main.o display.o event.o -lSDL_image -lpthreadmain.o: In function `main':main.cpp:(.text+0x66): undefined reference to `game_loop'main.cpp:(.text+0x75): undefined reference to `game_loop'event.o: In function `event_update()':event.cpp:(.text+0x2b): undefined reference to `game_loop'collect2: ld returned 1 exit statusmake: *** [SDL] Error 1   
  You put:extern int game_loop;in layout.h - you also need to put:int game_loop;in layout.cpp (or another .cpp file). The extern declaration just tells the compiler that game_loop is defined elsewhere and to leave it for the linker to find it once all the object files have been stitched together.However, since the only places you seem to need this variable are in main() and in event_update(), why not avoid the use of a global altogether and have event_update() return a value:bool event_update(){    while(SDL_PollEvent(&event))   {   if(event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE)  {  return false;   }   }    return true;}int main(){    bool game_loop=true;    while(game_loop)   {   game_loop=event_update();   }};  Why not have a check in the loop itself to decide when to quit?Simplified below:#include <iostream>#include <SDL/SDL.h>#include "display.h"#include "event.h"#include "layout.h"using namespace std;int main(int argc, char* args[]){   bool quit = false;SDL_init();   // while quit is false - continue game loopwhile(!quit){ Get_Input();  // take input from user Update_Game_Logic();   // update the game world Render();// render whatever needs rendering// if the escape key is pressed - end game loopif(IsKeyDown(Key_Escape))   quit = true;}SDL_exit();return 0;};Quote:However, since the only places you seem to need this variable are in main() and in event_update(), why not avoid the use of a global altogether and have event_update() return a value:Okay, this worked.  Thanks.   