title: compile and run c++ program with own header files in linux
body: <p>This is my first go at making my own header file. I am trying to make a simple Hello World program in C++ on Ubuntu. made 3 files as follows :</p>
  
  <p>//hello.h file</p>
  
  <pre><code>#ifndef HELLO_H
  #define HELLO_H
  
  //my own code
  
  void hello();
  
  #endif
  </code></pre>
  
  <p>//hello.cpp file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "hello.h"
  
  using namespace std;
  
  void hello()
  {
      cout &lt;&lt; "This line is printed from header.";
  }
  </code></pre>
  
  <p>//main.cpp file</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "hello.h"
  
  using namespace std;
  
  int main()
  {
      cout &lt;&lt; "in main" &lt;&lt; endl &lt;&lt; endl;
      hello();
      return 0;
  }
  </code></pre>
  
  <p>I've tried</p>
  
  <pre><code>g++ -I /home/Desktop/hello/ -c hello.cpp -o hello.o
  </code></pre>
  
  <p>to compile header file and this command worked.</p>
  
  <p>then, while doing</p>
  
  <pre><code>g++ -o main main.cpp
  </code></pre>
  
  <p>I am ending up with following error:</p>
  
  <pre><code>/tmp/ccb0DwHP.o: In function `main':
  main.cpp:(.text+0x2e): undefined reference to `hello()'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>Please suggest whether changes need to be made in any file or in any command in the terminal?</p>
  
  <p>thank you</p>