title: main.cpp:(.text+0x5f): undefined reference to
body: <p>I try to compile some exercise from a SDL guide.  </p>
  
  <p>I compile like this: </p>
  
  <pre><code>g++ -o main main.cpp -I/usr/local/include/SDL2 -L/usr/local/lib -lSDL2
  </code></pre>
  
  <p>and i get this:</p>
  
  <pre><code>/tmp/cci2rYNF.o: In function `main':
  main.cpp:(.text+0x5f): undefined reference to `Game::init(char const*, int, int, int, int, int)'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>and my code is:</p>
  
  <p>main.cpp</p>
  
  <pre><code>#include "Game.h"
  
  // our Game object
  Game* g_game = 0;
  
  int main(int argc, char* argv[])
  {
      g_game = new Game();
      g_game-&gt;init("Chapter 1", 100, 100, 640, 480, 0);
  
      while(g_game-&gt;running())
      {
      g_game-&gt;handleEvents();
      g_game-&gt;update();
      g_game-&gt;render();
      }
      g_game-&gt;clean();
  
      return 0;
  }
  </code></pre>
  
  <p>Game.h</p>
  
  <pre><code>#ifndef __Game__
  #define __Game__
  
  #include &lt;SDL.h&gt;
  
  class Game
  {
      public:
        Game() {}
        ~Game() {}
  
        bool init(const char* title, int xpos, int ypos, int width, int height, int flags);
        void render(){}
        void update(){}
        void handleEvents(){}
        void clean(){}
  
        // a function to access the private running variable
        bool running() { return m_bRunning; }
  
      private:
  
        SDL_Window* m_pWindow;
        SDL_Renderer* m_pRenderer;
        bool m_bRunning;
  };
  
  #endif // defined(__Game__) */
  </code></pre>
  
  <p>Game.cpp</p>
  
  <pre><code>#include "Game.h"
  
  bool Game::init(const char* title, int xpos, int ypos, int width, int height, int flags)
  {
      // attempt to initialize SDL
      if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
      {
      std::cout &lt;&lt; "SDL init success\n";
      // init the window
      m_pWindow = SDL_CreateWindow(title, xpos, ypos,
      width, height, flags);
  
      if(m_pWindow != 0) // window init success
      {
          std::cout &lt;&lt; "window creation success\n";
          m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
          if(m_pRenderer != 0) // renderer init success
          {
          std::cout &lt;&lt; "renderer creation success\n";
          SDL_SetRenderDrawColor(m_pRenderer,
          255,255,255,255);
          }
          else
          {
          std::cout &lt;&lt; "renderer init fail\n";
          return false; // renderer init fail
          }
      }
      else
      {
          std::cout &lt;&lt; "window init fail\n";
          return false; // window init fail
      }
      }
      else
      {
      std::cout &lt;&lt; "SDL init fail\n";
      return false; // SDL init fail
      }
      std::cout &lt;&lt; "init success\n";
      m_bRunning = true; // everything inited successfully, start main loop
  
      return true;
  }
  
  
  void Game::render()
  {
      SDL_RenderClear(m_pRenderer); // clear the renderer to the draw color
      SDL_RenderPresent(m_pRenderer); // draw to the screen
  }
  
  
  void Game::clean()
  {
      std::cout &lt;&lt; "cleaning game\n";
      SDL_DestroyWindow(m_pWindow);
      SDL_DestroyRenderer(m_pRenderer);
      SDL_Quit();
  }
  
  void Game::handleEvents()
  {
      SDL_Event event;
      if(SDL_PollEvent(&amp;event))
      {
        switch (event.type)
        {
          case SDL_QUIT:
            m_bRunning = false;
          break;
  
          default:
          break;
        }
      }
  }
  </code></pre>