【问题标题】:What library to link to for std::filesystem with Xcode使用 Xcode 为 std::filesystem 链接到什么库
【发布时间】:2025-12-01 14:30:02
【问题描述】:

Xcode 10.2 现在包含 <filesystem> 标头。但是,在使用std::filesystem 编写代码时,我遇到了很多额外的链接错误。

Undefined symbols for architecture x86_64:
  "std::__1::__fs::filesystem::path::__filename() const", referenced from:
      std::__1::__fs::filesystem::path::filename() const in dump_zip.cpp.o
      std::__1::__fs::filesystem::path::filename() const in libxp_parse.a(zipped.cpp.o)
      std::__1::__fs::filesystem::path::remove_filename() in libxp_parse.a(zipped.cpp.o)
      std::__1::__fs::filesystem::path::has_filename() const in libxp_parse.a(zipped.cpp.o)
      std::__1::__fs::filesystem::path::has_filename() const in libxp_parse.a(acf.cpp.o)

我认为需要链接一个额外的库以支持文件系统,但我无法确定它是什么或在哪里。知道它叫什么吗?

编辑:libc++ 说 libc++fs 是必需的——但是,它似乎没有随 Xcode 一起分发,至少不在默认搜索目录中。

【问题讨论】:

  • 在撰写此问题时,XCode 10.2 尚未公开发布。如果该库丢失,则很可能是一个错误,因此请提交雷达。

标签: c++ xcode c++17 libc++ std-filesystem


【解决方案1】:

Xcode 10.2 不包含实现<filesystem> 的库支持。之所以没有包含在 Xcode 10.2 中,是因为 <filesystem> 的实现当时并没有稳定的 ABI。

所以这种行为是预期的,但是如果错误更明确地说明为什么会发生这种情况会更好。

编辑:从 Xcode 11 和 MacOS 10.15 开始,<filesystem> 包含在主 libc++.dylib 中,无需链接任何其他库。

【讨论】: