experimental::filesystem linker error

The Filesystem TS is nothing to do with C++1z support, it is a completely separate specification not part of the C++1z working draft. GCC's implementation (in GCC 5.3 and later) is even available in C++11 mode.

You just need to link with -lstdc++fs to use it.

(The relevant library, libstdc++fs.a, is a static library, so as with any static library it should come after any objects that depend on it in the linker command.)

Update Nov 2017: as well as the Filesystem TS, GCC 8.x also has an implementation of the C++17 Filesystem library, defined in <filesystem> and in namespace std::filesystem (N.B. no "experimental" in those names) when using -std=gnu++17 or -std=c++17. GCC's C++17 support is not complete or stable yet, and until it's considered ready for prime time use you also need to link to -lstdc++fs for the C++17 Filesystem features.

Update Jan 2019: starting with GCC 9, the C++17 std::filesystem components can be used without -lstdc++fs (but you still need that library for std::experimental::filesystem).


If you are using cmake, add the following line to CMakeLists.txt:

link_libraries(stdc++fs)

So that cmake can link against the corresponding library.


With clang 4.0+, you need to link against libc++experimental.a

Make sure you're building with libc++ (not libstdc++) with the -stdlib=libc++ (as mentioned in the comments)

Tags:

C++

Gcc

C++17