I have a file where I am trying to include <filesystem>
. I have tried including <expirimental/filesystem>
and adding -lc++fs
to my compile command and this does not work. I used -std=c++17
and it still doesn't work. After googling this question, I have concluded that this is because my compiler has come with the <filesystem>
module (I use mingw gcc 6.3.0
). I was wondering if there is any solution to install the module without switching compilers (and no I am not going to switch to Linux, I will stick with Windows). Also I'm still somewhat new to Stack Overflow so don't mind if this question isn't in proper format.

- 73
- 7
-
"I have tried including `
`" Did you spell it that way? Because it's spelled `experimental`, not `expirimental`. Mind you, it should be just ` – ShadowRanger Apr 05 '23 at 00:35` for C++17 and higher, but in case your compiler is too old, it's worth checking your spelling. -
3GCC 6 is _very_ out of date. You should update it. Stable distros (I.e. real Linux) ship GCC 11, but 12-something is the newest. – Zoe Apr 05 '23 at 00:38
-
2Uninstall your current old version of MinGW and use msys2 to install the current version. If you use VSCode the official documentation tells you to do that. Here is teh msys2 site: [https://www.msys2.org/#installation](https://www.msys2.org/#installation) Here is the VSCode MinGW instructions: [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw) – drescherjm Apr 05 '23 at 00:39
-
1[Instructions for installing msys2](https://stackoverflow.com/a/30071634/4581301). Not only do you get up-to-date tools, you also get a massive ecosystem of pre-build libraries. If you ever need to work with a webserver, encrypt your data, or generally give your code a Boost, you'll be saving yourself a lot of work. – user4581301 Apr 05 '23 at 00:42
-
Side note: Consider installing clang rather than gcc. It has some extra code-sanitizing, error finding tools that haven't made it to gcc on Windows yet. `-fsanitize=address,undefined` can reduce the number of C++ questions you need to ask dramatically by telling you exactly what went wrong and where leaving you to only have to figure out the "How do I fix it?" part. Look like the genius in your programming class by using the same tools the pros do. – user4581301 Apr 05 '23 at 00:47
1 Answers
Using this library may require additional compiler/linker options. GNU implementation prior to 9.1 requires linking with
-lstdc++fs
and LLVM implementation prior to LLVM 9.0 requires linking with-lc++fs
.
MinGW is a port of GCC (GNU), and your version is old enough you need the link flag, but the link flag you need is -lstdc++fs
, not -lc++fs
. Between that and putting #include <filesystem>
at the top of your source files, it should work.
Of course, if you updated to a more recent release of MinGW (9.1 or higher), you wouldn't need the linker flag at all, and you'd probably get better C++17 support all around; 6.3 was released in December of 2016, predating the C++17 draft standard of March 2017 (that was accepted with minimal tweaks in December 2017), so it's almost certainly going to have other small issues with full C++17 support.

- 143,180
- 12
- 188
- 271