I got an error about something having 'already been defined in game.obj'. What do I do? : <p>While I was working with SDL2 in Visual Studio 2019, I came across a few errors:</p>

<pre><code>   1&gt;Source.obj : error LNK2005: "struct SDL_Window * game::gWindow" (?gWindow@game@@3PAUSDL_Window@@A) already defined in game.obj
   1&gt;Source.obj : error LNK2005: "struct SDL_Surface * game::gScreenSurface" (?gScreenSurface@game@@3PAUSDL_Surface@@A) already defined in game.obj
   1&gt;Source.obj : error LNK2005: "struct SDL_Surface * game::gImage" (?gImage@game@@3PAUSDL_Surface@@A) already defined in game.obj
</code></pre>

<p>I looked up how to fix it to no avail. I tried using externs, changing my game.h file but nothing worked. Just as some background info, I am trying to make a game engine type thing using SDL2 to help me in the future with game development. I would like to keep as much code as possible, not removing too much.</p>

<p>Here is my code:
Source.cpp</p>

<pre><code>    #include &lt;SDL.h&gt;
    #include "game.h"
    #include &lt;stdio.h&gt;

    int main(int argc, char* args[]) {
        if (!game::init()) { // SDL failed it initialize
            printf("error");
        }
        else { // SDL was able to initialize
            if (!game::loadMedia()) { // Could not load media
                printf("error");
            }
            else { // Could load media
                SDL_BlitSurface(game::gImage, NULL, game::gScreenSurface, NULL);
            }
        }
        return 0;
    }
</code></pre>

<p>game.cpp</p>

<pre><code>#include &lt;SDL.h&gt;
#include "game.h"
#include &lt;stdio.h&gt;

namespace game { //functions
    bool init() {
        bool success = true;
        if (SDL_Init(SDL_INIT_VIDEO) &lt; 0) {
            printf("SDL failed to initialize.\n");
            success = false;
        }
        else {
            gWindow = SDL_CreateWindow(
                "SDL Window (;", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN
            );
            if (gWindow == NULL)
            {
                printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
                success = false;
            }
            else
            {
                //Get window surface
                gScreenSurface = SDL_GetWindowSurface(gWindow);
            }
        }
        return success;
    }
    bool loadMedia() {
        // Loading success flag
        bool success = true;
        // File name of image
        const char* fileName = "mario.bmp";
        // Load splash image
        gImage = SDL_LoadBMP(fileName);
        if (gImage == NULL)
        {
            printf("Unable to load image '%s'! SDL Error: %s\n", fileName, SDL_GetError());
            success = false;
        }

        return success;
    }
}
</code></pre>

<p>and game.h</p>

<pre><code>#ifndef _GAME_H

namespace game {
    SDL_Window* gWindow;
    SDL_Surface* gScreenSurface;
    SDL_Surface* gImage;

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

    bool init();
    bool loadMedia();
}
#endif
</code></pre>

<p>Thanks in advance!</p>
