The latest versions of GCC and clang support C++17's std::filesystem (ref).
Why does this program not compile?
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <filesystem>
namespace fs = std::filesystem;
int main()
{
fs::create_directories("sandbox/1/2/a");
fs::create_directory("sandbox/1/2/b");
// fs::permissions("sandbox/1/2/b", fs::perms::remove_perms | fs::perms::others_all);
fs::create_directory("sandbox/1/2/c", "sandbox/1/2/b");
std::system("ls -l sandbox/1/2");
fs::remove_all("sandbox");
}
I tested it with the latest compiler versions from an online compiler, with the following compiler options:
clang++ prog.cc -Wall -Wextra -std=c++17
g++ prog.cc -Wall -Wextra -std=c++2a
From clang I get these linker errors:
/tmp/prog-9b6259.o: In function `main':
prog.cc:(.text+0x48): undefined reference to `std::__1::__fs::filesystem::__create_directories(std::__1::__fs::filesystem::path const&, std::__1::error_code*)'
prog.cc:(.text+0xad): undefined reference to `std::__1::__fs::filesystem::__create_directory(std::__1::__fs::filesystem::path const&, std::__1::error_code*)'
prog.cc:(.text+0x12f): undefined reference to `std::__1::__fs::filesystem::__create_directory(std::__1::__fs::filesystem::path const&, std::__1::__fs::filesystem::path const&, std::__1::error_code*)'
prog.cc:(.text+0x1b5): undefined reference to `std::__1::__fs::filesystem::__remove_all(std::__1::__fs::filesystem::path const&, std::__1::error_code*)'
clang-8: error: linker command failed with exit code 1 (use -v to see invocation)
1
If I decomment the line with fs::permissions, I get this compile time error:
prog.cc:11:49: error: no member named 'remove_perms' in 'std::__1::__fs::filesystem::perms'
fs::permissions("sandbox/1/2/b", fs::perms::remove_perms | fs::perms::others_all);
~~~~~~~~~~~^
I get similar errors from GCC.
What am I doing wrong? Is it possible that these compilers support the C++17 language, but not its libraries in their entirety?