I'm trying to install a C++ compiler with support for the filesystem library. The GCC-8 compiler I installed from Homebrew is meant to have this, yet upon running
#include <filesystem>
using std::filesystem::create_directories;
int main()
{
create_directories("sandbox/a/b");
return 0;
}
using the command
g++-8 browse.cpp -o test
I get the following output:
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");
^~~~~~~~~~~~~~~~~~
This is completely inexplicable to me, as even my code editor (VS Code) manages to find the declarations of the filesystem namespace, the source of which is in the compiler's directory.
edit: in response to the comments below, here's what happens when I try to do as recommended:
$ 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
It looks like there's some problem with my installation, but I can't decipher what it might be.