title: How to compile a c++ program in Linux?
body: <p>I made a file hi.cpp and I wrote the command given below:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  int main ()
  {
    cout &lt;&lt; "Hello World! ";
    cout &lt;&lt; "I'm a C++ program";
    return 0;
  }
  </code></pre>
  
  <p>then I ran it in my RHEL 6 machine with the following command</p>
  
  <pre><code>gcc hi.cpp
  </code></pre>
  
  <p>and I got some errors which are as follows: </p>
  
  <pre><code>[chankey@localhost ~]$ gcc hi.cpp
  /tmp/cc32bnmR.o: In function `main':
  hi.cpp:(.text+0xa): undefined reference to `std::cout'
  hi.cpp:(.text+0xf): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, const char*)'
  hi.cpp:(.text+0x19): undefined reference to `std::cout'
  hi.cpp:(.text+0x1e): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;std::char_traits&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, const char*)'
  /tmp/cc32bnmR.o: In function `__static_initialization_and_destruction_0(int, int)':
  hi.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::Init()'
  hi.cpp:(.text+0x51): undefined reference to `std::ios_base::Init::~Init()'
  /tmp/cc32bnmR.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
  collect2: ld returned 1 exit status
  [chankey@localhost ~]$ 
  </code></pre>
  
  <p>What do these errors denote? My code is correct then why am I getting errors?</p>