2

我正在使用 OS X 10.7.3。我已经玩了一段时间的 boost 标头,我想继续使用 Boost.Filesystem 库,但是它一直向我抛出这个消息:

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
4

2 回答 2

4

尝试

g++ -o test main.cpp -I/opt/local/include -L/opt/local/lib  -lboost_filesystem
于 2012-04-09T20:28:19.680 回答
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

作为编译器的标志。

于 2012-04-09T20:35:36.663 回答