MacOS Clang C ++ 17 header not found

I need to write a program using the (experimental) C++17 file system, but clang on my Mac (macOS 10.12.03) does not seem to contain the file system header.

Since I have to use C++17 , I cannot use alternatives such as the Boost library.

When I try to compile an example program that includes a file system and iostream (and writes to cout )

 #include <filesystem> #include <iostream> using namespace std; int main(){ cout << "test" << endl; } 

The following error message appears:

 >clang test.cpp -std=c++1z test.cpp:2:10: fatal error: 'filesystem' file not found #include <filesystem> ^ 1 error generated. 

When I try to use GCC 6.3 (installed via homebrew), I get:

 >gcc-6 test.cpp -std=c++17 test.cpp:2:22: fatal error: filesystem: No such file or directory #include <filesystem> ^ compilation terminated. 

I also tried using an experimental / file system that compiles with gcc , but seems to be trying to compile for iOS, leading to another error that seems to be related to iostream

 Undefined symbols for architecture x86_64: "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int) in ccd5QiVt.o "std::ios_base::Init::~Init()", referenced from: __static_initialization_and_destruction_0(int, int) in ccd5QiVt.o ld: symbol(s) not found for architecture x86_64 collect2: error: ld returned 1 exit status 

Version of my clang:

 >clang --version Apple LLVM version 8.0.0 (clang-800.0.42.1) Target: x86_64-apple-darwin16.4.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin 

I am grateful for any useful contribution, since I could not find anything that resolved my problem so far (although I may have searched for the wrong terms).

If you need more information, I gladly provided it, but I hope this is all included.

+28
c ++ gcc clang c ++ 17 macos
source share
7 answers

LibC ++, which is the standard C ++ library on OS X, has not moved <experimental/filesystem> to <filesystem> , but since the specification is unstable.

Hopefully the <filesystem> will be part of the Clang 6.0 release. (EDIT: we skipped 5.0)

+19
source share

In response to Max Raskin: I installed Xcode 10 Beta 4 from July 17, 2018, and in this version there is no "#include <experimental / file system>" or "#include <file system>".

The release notes also do not mention lib c ++ 17 <file system>. The release notes mention that in Xcode 10 there are: <any>, <option> and <option>.

An example of the location of the included file:

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

+6
source share

Xcode 11 beta now includes <filesystem> . Unlike other answers pointing to beta support in Xcode 10, Apple mentioned this in release notes .

Also mentioned in the release notes, this is only supported by iOS 13, macOS 10.15, watchOS 6 and tvOS 13.

+3
source share

Includes declarations, but get definitions that you should also associate with -lstdC ++ fs (for libstdC ++), or I don't know (for libC ++). If someone knows, maybe they can update this answer?

For libC ++ you need to associate with -lc++experimental

+2
source share

EDIT

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

Clang now supports c ++ 17 library for iOS 13, macOS 10.15, watchOS 6 and tvOS 13. (50988273)

Here, hoping it means staying this time!

OLD RESPONSE

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

EDIT:

Loaded Xcode 10.2 (10E125) aaaaand ... <filesystem> disappeared again. No mention in release notes . If you have a version of Xcode that contains <filesystem> (e.g. beta 4, which I mentioned earlier), copying the file will work just fine:

 $ 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/ 

Keep in mind, of course, that every Xcode update will very likely break this workaround and make another copy necessary. There is also probably a good reason why the beta version did not make it into the release . Be careful ...

+2
source share

If anyone is still interested, the beta version of Xcode 10 comes with libc ++, which has an experimental / file system

UPDATE of one of the beta versions of Xcode 10 that came with it, possibly by accident, in Xcode 10.1, unfortunately, it is not :(

+1
source share

Xcode 9.4 installed - no

but homegrown came to the rescue with llvm 6

brew update install brew llvm

and with the change in PATH I was far away.

0
source share

All Articles