title: Error message "Undefined reference for std:string"
body: <p>I have some code that reads the name of the file from arguments and outputs that file into the command line:</p>
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;string.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(int argc, char* argv[])
  {
      if (argc != 2)
      {
          printf(&quot;Use: .exe [filename you want printed out]\n&quot;);
      }
  
      char* name = argv[1];
      string line;
  
      printf(&quot;filename:%s\n&quot;, name);
  
      ifstream myfile(name);
  
      if (myfile.is_open())
      {
          while (getline(myfile, line))
          {
              cout &lt;&lt; line &lt;&lt; '\n';
          }
          myfile.close();
      }
  }
  </code></pre>
  <p>However, when I try to compile my code it outputs the following error:</p>
  <pre class="lang-none prettyprint-override"><code>hello.cpp:(.text+0x5a): undefined reference to `std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::basic_string()'
  hello.cpp:(.text+0x93): undefined reference to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::basic_ifstream(char const*, std::_Ios_Openmode)'
  hello.cpp:(.text+0xa2): undefined reference to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::is_open()'
  hello.cpp:(.text+0xbf): undefined reference to `std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::getline&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;(std::basic_istream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;&amp;)'
  hello.cpp:(.text+0xd4): undefined reference to `std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::operator bool() const'
  hello.cpp:(.text+0xe9): undefined reference to `std::cout'
  hello.cpp:(.text+0xee): undefined reference to `std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp; std::operator&lt;&lt; &lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;(std::basic_ostream&lt;char, std::char_traits&lt;char&gt; &gt;&amp;, std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; const&amp;)'
  hello.cpp:(.text+0xfb): 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;, char)'
  hello.cpp:(.text+0x10c): undefined reference to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::close()'
  hello.cpp:(.text+0x11b): undefined reference to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::~basic_ifstream()'
  hello.cpp:(.text+0x12a): undefined reference to `std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::~basic_string()'
  hello.cpp:(.text+0x152): undefined reference to `std::basic_ifstream&lt;char, std::char_traits&lt;char&gt; &gt;::~basic_ifstream()'
  hello.cpp:(.text+0x166): undefined reference to `std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;::~basic_string()'
  /tmp/cc0aneAi.o: In function `__static_initialization_and_destruction_0(int, int)':
  hello.cpp:(.text+0x1a9): undefined reference to `std::ios_base::Init::Init()'
  hello.cpp:(.text+0x1be): undefined reference to `std::ios_base::Init::~Init()'
  /tmp/cc0aneAi.o:(.data.rel.local.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
  collect2: error: ld returned 1 exit status
  </code></pre>
  <p>What's it telling me? How can I fix it?</p>