title: Linking/compiling a program that uses boost/filesystem.hpp
body: <p>I'm trying to use the boost/filesystem library in some code that I am writing. I seem to be having a hard time getting it to compile. I'm running Debian Wheezy, and have boost version 1.49(which is what comes if you install using apt-get). I'm trying to compile an example that is available with the documentation</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/filesystem.hpp&gt;
  using namespace boost::filesystem;
  
  int main(int argc, char* argv[])
  {
    if (argc &lt; 2)
    {
      std::cout &lt;&lt; "Usage: tut1 path\n";
      return 1;
    }
    std::cout &lt;&lt; argv[1] &lt;&lt; " " &lt;&lt; file_size(argv[1]) &lt;&lt; '\n';
    return 0;
  }
  </code></pre>
  
  <p>I use the following command:</p>
  
  <pre><code>g++ temp.cc -o temp /usr/lib/libboost_filesystem.a
  </code></pre>
  
  <p>I get a number of errors such as:</p>
  
  <pre><code>/usr/lib/libboost_filesystem.a(operations.o): In function `boost::filesystem3::detail::dir_itr_close(void*&amp;, void*&amp;)':
  (.text+0x4d): undefined reference to `boost::system::system_category()'
  /usr/lib/libboost_filesystem.a(operations.o): In function `boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_iterator&amp;, boost::system::error_code*)':
  (.text+0xe3): undefined reference to `boost::system::system_category()'
  </code></pre>
  
  <p>This is probably some linking error right? Any ideas on how I could solve it?</p>
  
  <p><strong>UPDATE #1</strong>:
  I tried running it with the -lboost_filesyste and -L /usr/lib. It gives me the following error:</p>
  
  <pre><code>/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o: In function `_start':
  (.text+0x20): undefined reference to `main'
  </code></pre>