Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What library to link to for std::filesystem with Xcode

Xcode 10.2 now includes the <filesystem> header. However, when writing code using std::filesystem, I'm running into a lot of extra link errors.

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)

I believe an extra library needs to be linked for filesystem support, but I can't identify what or where it is. Any idea what it is called?

EDIT: libc++ says that libc++fs is required- however, that doesn't seem to be distributed with Xcode, at least not in the default search directories.

like image 459
leecbaker Avatar asked Dec 24 '22 00:12

leecbaker


1 Answers

Xcode 10.2 does not contain the library support to implement <filesystem>. The reason why it was not included in Xcode 10.2 is that the implementation of <filesystem> did not have a stable ABI at the time.

So the behavior is expected, however it would be nicer if the error was more explicit about why this happens.

EDIT: As of Xcode 11 and MacOS 10.15, <filesystem> is shipped in the main libc++.dylib and there's no need to link any additional library.

like image 78
Louis Dionne Avatar answered Jan 06 '23 08:01

Louis Dionne