c++17 `filesystem` 不是命名空间名称

c++17 `filesystem` is not a namespace-name

我想知道为什么在下面的代码中找不到命名空间 filesystem:

g++ -std=c++17 main.cpp -lstdc++

// #include <filesystem>   <- error, so changed to the following:
#include <experimental/filesystem>

namespace fs = std::filesystem;

int main()
{
    return 0;
}

错误:

main.cpp:3:21: error: ‘filesystem’ is not a namespace-name
 namespace fs = std::filesystem;
                     ^
main.cpp:3:31: error: expected namespace-name before ‘;’ token
 namespace fs = std::filesystem;

gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.5)

<experimental/..> 表示实验命名空间:

namespace fs = std::experimental::filesystem;

参见:http://en.cppreference.com/w/cpp/experimental/fs/path

GCC 5.4.0 于 2016 年 6 月发布;在 C++17 标准被采用之前一年多。它和它的 libstdc++ 版本对 C++17 的支持非常有限。可以看到 GCC 何时添加了 C++17 语言特性 here and when libstdc++ added C++17 standard library features here.

在 GCC 5.4 发布时,文件系统库尚未在 std::filesystem 命名空间中实现。它与该版本中包含的任何其他 headers 一起位于 std::experimental 命名空间中。