Linker problems when building boost::filesystem example

I'm trying to test out the example on the tutorial page:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <boost/filesystem.hpp>
using namespace boost::filesystem;

int main(int argc, char* argv[])
{
  if (argc < 2)
  {
    std::cout << "Usage: tut1 path\n";
    return 1;
  }
  std::cout << argv[1] << " " << file_size(argv[1]) << '\n';
  return 0;
}


These are errors:
/tmp/ccZQrZZp.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x115): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x11f): undefined reference to `boost::system::generic_category()'
test.cpp:(.text+0x129): undefined reference to `boost::system::system_category()'
/tmp/ccZQrZZp.o: In function `boost::filesystem::file_size(boost::filesystem::path const&)':
test.cpp:(.text._ZN5boost10filesystem9file_sizeERKNS0_4pathE[_ZN5boost10filesystem9file_sizeERKNS0_4pathE]+0x15): undefined reference to `boost::filesystem::detail::file_size(boost::filesystem::path const&, boost::system::error_code*)'
/tmp/ccZQrZZp.o: In function `boost::filesystem::path::path<char*>(char* const&, boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<char*>::type>, void>::type*)':
test.cpp:(.text._ZN5boost10filesystem4pathC2IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE[_ZN5boost10filesystem4pathC5IPcEERKT_PNS_9enable_ifINS0_11path_traits11is_pathableINS_5decayIS4_E4typeEEEvE4typeE]+0x13): undefined reference to `boost::filesystem::path::codecvt()'
collect2: error: ld returned 1 exit status



And this is the command I'm using:
g++ -I /path/boost_1_55_0 -lboost_system -lboost_filesystem test.cpp


I've also tried different variations of that based on what I could find on Google, no luck. Any help is appreciated, thanks.
Figured it out, when compiling do
g++ test.cpp -lboost_system -lboost_filesystem


Apparently the order matters with g++
Last edited on
Topic archived. No new replies allowed.