macOS Clang C++17 filesystem header not found

前端 未结 8 643
借酒劲吻你
借酒劲吻你 2020-12-14 06:30

I need to write a program using the (experimental) C++17 filesystem library but clang on my Mac (macOS 10.12.03) doesn\'t seem to

相关标签:
8条回答
  • 2020-12-14 06:40

    Xcode 11 Beta now includes <filesystem>. Unlike the other answers indicating beta support in Xcode 10, Apple has mentioned this in the release notes.

    Also mentioned in the release notes, is this is only supported by iOS 13, macOS 10.15, watchOS 6, and tvOS 13. You will only be able to use std::filesystem for projects targeting these versions or later.

    0 讨论(0)
  • 2020-12-14 06:41

    Including gets you the declarations, but to get the definitions you also have to link with -lstdc++fs (for libstdc++) or I don't know (for libc++). If someone knows, maybe they could update this answer?

    For libc++ you need to link with -lc++experimental

    0 讨论(0)
  • 2020-12-14 06:43

    I installed XCode 9.4 - no <filesystem>

    But Homebrew came to the rescue with LLVM 6

    brew update
    brew install llvm
    

    And with a change in PATH, I was away.

    0 讨论(0)
  • 2020-12-14 06:46

    Libc++, which is the C++ standard library on OS X, has not moved <experimental/filesystem> to <filesystem> yet because the specification is not stable.

    Hopefully <filesystem> will be a part of the Clang 6.0 release. (We missed 5.0)

    0 讨论(0)
  • 2020-12-14 06:54

    In reply to Max Raskin: I've installed Xcode 10 Beta 4, from July 17, 2018, and this version does not have "#include <experimental/filesystem>" or "#include <filesystem>".

    The release notes also do not mention libc++17 <filesystem>. The release notes do mention that the following are in Xcode 10: <any>, <optional>, and <variant>.

    Example include file location:

    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/experimental

    0 讨论(0)
  • 2020-12-14 06:55

    EDIT

    As mentioned in another answer <filesystem> is available in Xcode 11 Beta according to the release notes:

    Clang now supports the C++17 <filesystem> library for iOS 13, macOS 10.15, watchOS 6, and tvOS 13. (50988273)

    Here's hoping it's meant to stay this time!

    OLD ANSWER

    Just checked Xcode 10.2 Beta 4 and it has regular <filesystem>! For the curious, it's in /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/.

    EDIT:

    Downloaded Xcode 10.2 (10E125) aaaaand ... <filesystem> is gone again. No mention whatsoever in the release notes. If you happen to have an Xcode version that contains <filesystem> lying around (like the Beta 4 I mentioned earlier) copying the file over seems to work okay:

    $ sudo cp /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/filesystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/
    

    Mind you, of course, every Xcode update will very likely break this workaround and make another copy necessary. Also, there is probably a good reason why the beta implementation didn't make it into the release. Proceed with caution...

    0 讨论(0)
提交回复
热议问题