title: C++ Undefined reference to `main (.text+0x24)
body: <p>I have some problems with compiling my program since adding .h files to it.</p>
  <p>The error I'm getting looks like this.</p>
  <pre><code>/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
  (.text+0x24): undefined reference to `main'
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p>I've tried adding int main() to minesClass.cpp but it didn't fix the problem</p>
  <p>Program contains three files: main.cpp, minesClass.h, minesClass.cpp</p>
  <p>main.cpp</p>
  <pre><code>#include &quot;minesClass.h&quot;
  #include &lt;iostream&gt; 
  #include &lt;time.h&gt;
  
  #ifndef MINESBOARD_H__
  #define MINESBOARD_H__
  
  int main()
  {
    MinesweeperBoard board(10, 10, GameMode::NORMAL);
  
    board.getMines();
  
    board.debug_display();
  
  }
  
  #endif
  </code></pre>
  <p>minesClass.cpp</p>
  <pre><code>#include &quot;minesClass.h&quot;
  
  #define MINESBOARD_H__
  #ifndef MINESBOARD_H__
  
  MinesweeperBoard::MinesweeperBoard(int width, int height, GameMode mode)
  {
    for (int column = 0; column &lt; height; column++) 
    {
      for (int row = 0; row &lt; width; row++)
      {
        board[column][row].hasFlag = false;
        board[column][row].isRevealed = false;
      }
    }
  }
  
  void MinesweeperBoard::getMines(GameMode mode)  
  {
      srand(time(NULL));
      
      switch (mode)
      {
      case 1:
          EASY;
  
          for (int column = 0; column &lt; height; column++)
          {
              for (int row = 0; row &lt; width; row++)
              {
                  int minePropability = RAND_MAX * 0.1;
                  int num = rand();
  
                  if (num &lt;= minePropability)
                  {
                      board[column][row].hasMine = 1;
                  }
                  else
                      board[column][row].hasMine = 0;
              }
          }
  
          break;
      case 2:
          NORMAL;
  
          for (int column = 0; column &lt; height; column++)
          {
              for (int row = 0; row &lt; width; row++)
              {
                  int minePropability = RAND_MAX * 0.2;
                  int num = rand();
  
                  if (num &lt;= minePropability)
                  {
                      board[column][row].hasMine = 1;
                  }
                  else
                      board[column][row].hasMine = 0;
              }
          }
  
          break;
      case 3:
          HARD;
  
          for (int column = 0; column &lt; height; column++)
          {
              for (int row = 0; row &lt; width; row++)
              {
                  int minePropability = RAND_MAX * 0.3;
                  int num = rand();
  
                  if (num &lt;= minePropability)
                  {
                      board[column][row].hasMine = 1;
                  }
                  else
                      board[column][row].hasMine = 0;
              }
          }
  
          break;
      case 4:
          DEBUG;
  
          break;
      default:
  
          break;
      }
      
  }
  
  void MinesweeperBoard::debug_display() const
  {
  
  for (int column = 0; column &lt; height; column++)
    {
      for (int row = 0; row &lt; width; row++)
      {
        std::cout &lt;&lt; &quot;[&quot;;
        if (board[column][row].hasMine)
          std::cout &lt;&lt; &quot;M&quot;;
        else
          std::cout &lt;&lt; &quot;.&quot;;
        if (board[column][row].isRevealed)
          std::cout &lt;&lt; &quot;o&quot;;
        else
          std::cout &lt;&lt; &quot;.&quot;;
        if (board[column][row].hasFlag)
          std::cout &lt;&lt; &quot;f&quot;;
        else
          std::cout &lt;&lt; &quot;.&quot;;
        std::cout &lt;&lt; &quot;]&quot;;
      }
      std::cout &lt;&lt; width&lt;&lt;height&lt;&lt;std::endl;
    }
  
  }
  
  #endif
  
  </code></pre>
  <p>minesClass.h</p>
  <pre><code>#include &lt;iostream&gt;
  
  #define MINESBOARD_H__
  #ifndef MINESBOARD_H__
  
  enum GameMode
  {
    DEBUG,
    EASY,
    NORMAL,
    HARD
  };
  
  struct Field
  {
    bool hasMine;
    bool hasFlag;
    bool isRevealed;
  };
  
  class MinesweeperBoard
  {
  
    Field board[100][100];
    int width;
    int height;
    
  public:
  
    MinesweeperBoard(int width, int height, GameMode mode);
  
    void debug_display() const;
    
    void getMines(GameMode mode);
  };
  
  #endif
  
  </code></pre>
  <p>I've looked through similar questions asked with &quot;undefined reference to `main&quot; but most of them were based on missing int main().</p>