【问题标题】:Attempting to use Boost.Filesystem however it doesn't seem to link?尝试使用 Boost.Filesystem 但它似乎没有链接?
【发布时间】:2012-04-09 20:19:31
【问题描述】:

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

【问题讨论】:

    标签: c++ boost filesystems boost-filesystem


    【解决方案1】:

    试试

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

    【讨论】:

    • 它返回了这个错误: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
    • 看来您也缺少 libboost_system。只需添加-lboost_system
    【解决方案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.
    

    因此,如果您在 ~/libs/ 中有一个名为 mylib 的库,并且需要使用位于 ~/include 中的头文件,则可以通过

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

    作为编译器的标志。

    【讨论】:

    • 谢谢,这让一切变得更加清晰。老实说,我不知道它们实际上是什么。干杯。
    猜你喜欢
    • 2020-06-28
    • 2018-08-28
    • 2011-12-13
    • 1970-01-01
    • 2016-05-31
    • 2016-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多