Why does GCC not seem to have the filesystem standard library?
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.
how to use std::filesystem on gcc 8?
Add the filesystem library as an argument to your compiler that will be forwarded to the linker. Also make sure you are using C++17. Both g++ and clang++ accepts this particular format:
--std=c++17 -lstdc++fs
How can I install the filesystem C++ library with minGW?
The C++ filesystem
library was introduced in C++17, but your compiler might be configured to use an earlier version of the language by default. Try using the -std=c++17
option.
Link errors using filesystem members in C++17
Add the flag -lstdc++fs
:
$ g++-7 test.cpp -std=c++17 -lstdc++fs
gcc 7.2 supports C++17 experimental filesystem
namespace only. I do not know, maybe gcc 7.3 supports std filesystem
namespace already.
fatal error: filesystem: No such file or directory
It seems you have to include <filesystem>
like this:
#include <experimental/filesystem>
Don't forget to add -lstdc++fs
as a GCC flag!
Here is the proof:
Coliru
If that doesn't work, then that probably means that you don't have filesystem
in your configuration.
Also, as @MartinR. pointed out, the experimental
is no longer needed in GCC 8+.
std::filesystem example not compiling on c++ 17
There was a defect in C++17 standard that didn't allow operator<<
to be called with std::filesystem::directory_entry
, reported in LWG 3171. It's now fixed as defect report, but it seems clang only fixed it in version 14: https://godbolt.org/z/3arTcGYvY. gcc seems to have backported the fix to all versions that support std::filesystem
(that is, gcc9.1 and up): https://godbolt.org/z/fh7cdMxso
c++ 17 std::filesystem can not run on other (windows 10) computer
Did you check that the
libstdc++-6.dll
Is available or the relevant libraries are statically included static linked libs
Related Topics
Copy Constructor of Derived Qt Class
Access Child Members Within Parent Class, C++
Constructor with By-Value Parameter & Noexcept
Virtual Functions Default Parameters
Multithreading on Dual Core MAChine
Why Default Return Value of Main Is 0 and Not Exit_Success
Create Objects in Conditional C++ Statements
Send Binary File Over Tcp/Ip Connection
Volatile Struct = Struct Not Possible, Why
C and C++ Functions Without a Return Statement
Why Derive from a Concrete Class Is a Poor Design
Is the Result of a Cast an Rvalue
Why Is the Address of This Volatile Variable Always at 1
How to Compile a C++ Code in Gcc (G++) to See The Name Mangling on Overloaded Functions