试图使用Boost.Filesystem然而它似乎没有链接?

时间:2012-04-09 20:19:32

标签: c++ boost filesystems boost-filesystem

我使用OS X 10.7.3。我已经玩了一段时间的升级标题了,我想继续使用Boost.Filesystem lib,但它不断向我发送这条消息:

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

当我尝试使用此编译时,我得到了这个:

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

所以我回到了boost.org教程并尝试了正则表达式示例。它完美地使用了这个:

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

2 个答案:

答案 0 :(得分:4)

g++ -o test main.cpp -I/opt/local/include -L/opt/local/lib  -lboost_filesystem

答案 1 :(得分:4)

您的编译器标志似乎有点过时了。一般来说,以下是:

-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.

所以,如果在〜/ libs /中有一个名为mylib的库,并且需要使用位于〜/ include中的头文件,那么你将通过

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

作为编译器的标志。