c++gccraspberry-pic++17gcc6

Why does GCC not seem to have the filesystem standard library?


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 ??


Solution

  • 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.