g ++-8中的“错误:未声明'std :: filesystem'”

时间:2018-07-20 13:03:59

标签: c++ macos filesystems homebrew c++17

我正在尝试安装支持文件系统库的C ++编译器。我从Homebrew安装的GCC-8编译器本应具有此功能,但在运行

#include <filesystem>
using std::filesystem::create_directories;

int main()
{
    create_directories("sandbox/a/b");
    return 0;
}

使用命令

g++-8 browse.cpp -o test

我得到以下输出:

browse.cpp:3:12: error: 'std::filesystem' has not been declared
 using std::filesystem::create_directories;
            ^~~~~~~~~~
browse.cpp: In function 'int main()':
browse.cpp:7:5: error: 'create_directories' was not declared in this scope
     create_directories("sandbox/a/b");
     ^~~~~~~~~~~~~~~~~~

这对我来说完全是莫名其妙的,因为即使我的代码编辑器(VS Code)也设法找到文件系统名称空间的声明,该文件系统名称空间的源位于编译器的目录中。

编辑:针对以下评论,这是我尝试按照建议进行操作时发生的情况:

$ g++-8 browse.cpp -o test -std=c++17
Undefined symbols for architecture x86_64:
  "std::filesystem::create_directories(std::filesystem::__cxx11::path const&)", referenced from:
      _main in ccsGsUhu.o
  "std::filesystem::__cxx11::path::_M_split_cmpts()", referenced from:
      std::filesystem::__cxx11::path::path<char [8], std::filesystem::__cxx11::path>(char const (&) [8], std::filesystem::__cxx11::path::format) in ccsGsUhu.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

看来我的安装有问题,但我无法理解它可能是什么。

0 个答案:

没有答案