36

i'm facing a problem with filesystem library, it should be included in c++17 compiler, after 2 days i tried to install gcc-7.0.2 in raspberry pi but it didn't work, it couldn't recognize the command gcc-7 or g++-7 or even -std=c++17 so i had to install g++-6 and gcc-6 using apt-get install anyway, after installing the 6 version the compiler include c++17. i'm using codeblocks as IDE, i had to add a new compiler and add the option -std=c++17 to enable it,but in the main code when i include the filesystem library it says no such file or directory.

my question is, how i can add the c++17 compiler and its library (like filesystem) correctly ??

6
  • 7
    Just because the switch says "C++17" doesn't mean that it implements all of C++17. Commented Aug 24, 2017 at 17:10
  • 5
    More specifically, it can only implement the language parts. The library parts are outside the compiler's purview. Commented Aug 24, 2017 at 17:12
  • 4
    @IgnacioVazquez-Abrams: Well, the compiler switches are also used to activate the library parts, since they're included with the compiler in the distro. But you're right that libstdc++ is updated separately from gcc. Commented Aug 24, 2017 at 17:15
  • @Nicol It's not updated seperately at all: specific GCC releases are quite tightly bound to specific libstdc++ snapshots. The version numbering works slightly different and both are developed semi-independently (as language feature implementation in the compiler permits). Commented Aug 22, 2018 at 14:28
  • 1
    @Rick you'll probably have two even though the newer one should work as a drop-in replacement for the old one. Commented Nov 27, 2018 at 15:44

2 Answers 2

75

GCC v7 still does not implement <filesystem> but it does have the Filesystem Technical Specification which is in <experimental/filesystem>

#include <experimental/filesystem>

// for brevity
namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p = "/path/to/my/file"; // etc...
}

This is also available in GCC v6.

To link with the library you need to add -lstdc++fs to the command line.

Note: There may be some minor differences between the current Technical Specification and the final draft of <filesystem> that is decided upon by the Standards Committee.

Note 2: GCC v8 now implements <filesystem> with the -std=c++17 flag.

Sign up to request clarification or add additional context in comments.
8

First you should take at look at C++17 Support in GCC

GCC 8

Runtime Library (libstdc++)

  • Improved experimental support for C++17, including the following features:
    • Deduction guides to support class template argument deduction.
    • std::filesystem implementation.
    • std::char_traits<char> and std::char_traits<wchar_t> are usable in constant expressions.
    • std::to_chars and std::from_chars (for integers only, not for floating point types).

src: https://gcc.gnu.org/gcc-8/changes.html#libstdcxx

GCC 9

Runtime Library (libstdc++)

  • Improved support for C++17, including:
    • The C++17 implementation is no longer experimental.
    • Parallel algorithms and <execution> (requires Thread Building Blocks 2018 or newer).
    • <memory_resource>.
    • Using the types and functions in <filesystem> does not require linking with -lstdc++fs now.

src: https://gcc.gnu.org/gcc-9/changes.html#libstdcxx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.