尝试使用Boost.Filesystem的但它似乎没有联系呢?(Attempting to use

2019-09-16 10:18发布

我使用的是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

Answer 1:

尝试

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


Answer 2:

你的编译器标志似乎有点过。 一般来说,下列保持:

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

所以,如果你有一个名为MYLIB在〜/库库/并需要使用位于〜/包含头文件,你会通过

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

作为标志的编译器。



文章来源: Attempting to use Boost.Filesystem however it doesn't seem to link?