2

I'm using OS X 10.7.3. I've been playing with the boost headers for a while now and i wanted to move onto using the Boost.Filesystem lib however it keeps throwing this message at me:

Undefined symbols for architecture x86_64:
  "boost::system::generic_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
      boost::filesystem3::detail::create_directories(boost::filesystem3::path const&,     boost::system::error_code*)in libboost_filesystem.a(operations.o)
      boost::filesystem3::detail::canonical(boost::filesystem3::path const&,     boost::filesystem3::path const&, boost::system::error_code*)in     libboost_filesystem.a(operations.o)
  "boost::system::system_category()", referenced from:
      __static_initialization_and_destruction_0(int, int)in ccOhIhNG.o
      (anonymous namespace)::error(bool, boost::system::error_code const&,     boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char,     std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
      (anonymous namespace)::error(bool, boost::filesystem3::path const&,     boost::system::error_code*, std::basic_string<char, std::char_traits<char>,     std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
      (anonymous namespace)::error(bool, boost::filesystem3::path const&,     boost::filesystem3::path const&, boost::system::error_code*, std::basic_string<char,     std::char_traits<char>, std::allocator<char> > const&)in libboost_filesystem.a(operations.o)
      boost::filesystem3::detail::dir_itr_close(void*&, void*&)in     libboost_filesystem.a(operations.o)
      boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_itera    tor&, boost::system::error_code*)in libboost_filesystem.a(operations.o)
      boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_itera    tor&, boost::filesystem3::path const&, boost::system::error_code*)in     libboost_filesystem.a(operations.o)
      ...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

i get this when i try to compile using this:

g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_filesystem.a

So i went back to the boost.org tutorials and tried out the regex example. It worked perfectly using this:

g++ -o test main.cpp -I -l/opt/local/include ~/boost/libs/libboost_regex.a
ildjarn
  • 62,044
  • 9
  • 127
  • 211
Richard Bamford
  • 1,835
  • 3
  • 15
  • 19

2 Answers2

4

try

g++ -o test main.cpp -I/opt/local/include -L/opt/local/lib  -lboost_filesystem
juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • It returned this error: `Undefined symbols for architecture x86_64: "boost::system::generic_category()", referenced from: __static_initialization_and_destruction_0(int, int)in ccWyCTY8.o "boost::system::system_category()", referenced from: __static_initialization_and_destruction_0(int, int)in ccWyCTY8.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status ` – Richard Bamford Apr 09 '12 at 20:31
  • 1
    it looks like you're missing libboost_system too. Just add `-lboost_system`. – juanchopanza Apr 09 '12 at 20:32
4

Your compiler flags seem a bit off. Generally, the following hold:

-I // Sets the path for the relevant header files
-L // Sets the path where your libraries reside
-l // specifies the library you want to link against.

So, if you have a library called mylib in ~/libs/ and need to use header files located in ~/include, you'd pass

-I ~/include -L ~/libs -lmylib

as flags to the compiler.

pmcs
  • 1,123
  • 10
  • 16