title: Already Defined / Multiple Object Definitions / Visual Studio
body: <p>I'm following along with a video tut on SDL. When I do exactly as he has done, by putting an SDL_Texture* in the Game.h and use the object in Game.cpp, I get an error about multiple definitions. Yet, the video creator has no error of such. I can, however, copy and paste the SDL_Texture* to the .cpp and it work just fine. </p>
  
  <p>Why is it that the same code will work on one, but not another machine, in Visual Studio</p>
  
  <p>Game.cpp</p>
  
  <pre><code>    #include "Game.h"
  
  
  Game::Game()
  {
  
  
  }
  
  Game::~Game()
  {
  
  
  }
  
  void Game::init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen)
  {
      int flags = 0;
      if (fullscreen)
      {
          flags = SDL_WINDOW_FULLSCREEN;
      }
  
      if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
      {
          std::cout &lt;&lt; "Successfully Initialized Subsystem . . . " &lt;&lt; std::endl;
  
          window = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
              if (window)
              {
                  std::cout &lt;&lt; "Successfully Created Window . . . " &lt;&lt; std::endl;
              }
              else
              {
                  std::cout &lt;&lt; "Something went wrong. Error: " &lt;&lt; SDL_GetError() &lt;&lt; std::endl;
              }
  
              renderer = SDL_CreateRenderer(window, -1, 0);
              if (renderer)
              {
                  SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
                  std::cout &lt;&lt; "Successfully Created Renderer . . . " &lt;&lt; std::endl;
              }
              else
              {
                  std::cout &lt;&lt; "Something went wrong. Error: " &lt;&lt; SDL_GetError() &lt;&lt; std::endl;
              }
  
              is_running = true;
      }
      else
      {
          is_running = false;
      }
  
      SDL_Surface* surf_temp = IMG_Load("assets/player.png");
      tex_player = SDL_CreateTextureFromSurface(renderer, surf_temp);
      SDL_FreeSurface(surf_temp);
  
  
  }
  
  
  void Game::event_handle()
  {
      SDL_Event event;
      SDL_PollEvent(&amp;event);
      switch (event.type)
      {
      case SDL_QUIT:
          is_running = false;
  
      }
  
  }
  
  void Game::update()
  {
      cnt++;
      std::cout &lt;&lt; cnt &lt;&lt; std::endl;
  
  
  }
  
  
  
  void Game::render()
  {
      SDL_RenderClear(renderer);
      SDL_RenderCopy(renderer, tex_player, NULL, NULL); 
      SDL_RenderPresent(renderer);
  
  }
  
  void Game::clean()
  {
      SDL_DestroyWindow(window);
      SDL_DestroyRenderer(renderer);
      SDL_Quit();
      std::cout &lt;&lt; "Game cleaned . . . " &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Game.h</p>
  
  <pre><code>#include "SDL.h"
  #include "SDL_image.h"
  #include &lt;iostream&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string&gt;
  
  
  
  SDL_Texture* tex_player;
  
  class Game 
  {
  
  public:
      Game();
      ~Game();
  
      void init(const char* title, int xpos, int ypos, int width, int height, bool fullscreen);
  
      void event_handle();
      void update();
      void render();
      void clean();
  
      bool running() { return is_running; }
  
  
  private:
  
      int cnt;
  
      bool is_running;
      SDL_Window *window;
      SDL_Renderer *renderer;
  
  
  };
  </code></pre>
  
  <p>main.cpp</p>
  
  <pre><code>#include "Game.h"
  
  
  
  Game *game = nullptr;
  
  int main(int argc, char *argv[])
  {
      game = new Game();
  
      game-&gt;init("Yeah", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, false);
      while (game-&gt;running())
      {
          game-&gt;event_handle();
          game-&gt;update();
          game-&gt;render();
      }
  
      game-&gt;clean();
  
      return 0;
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>1&gt;------ Build started: Project: SDL_Template, Configuration: Debug Win32 ------
  1&gt;main.cpp
  1&gt;LINK : C:\Users\Onion\documents\visual studio 2017\Projects\SDL_Template\Debug\SDL_Template.exe not found or not built by the last incremental link; performing full link
  1&gt;main.obj : error LNK2005: "struct SDL_Texture * tex_player" (?tex_player@@3PAUSDL_Texture@@A) already defined in Game.obj
  1&gt;C:\Users\Onion\documents\visual studio 2017\Projects\SDL_Template\Debug\SDL_Template.exe : fatal error LNK1169: one or more multiply defined symbols found
  1&gt;Done building project "SDL_Template.vcxproj" -- FAILED.
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>