0

Having troubles accessing the filesystem namespace -

Problem:

  • "Symbol 'filesystem' could not be resolved"`

Leading Research:

  1. How can I get the list of files in a directory using C or C++? - Stack Overflow

  2. C++17 Filesystem - Codingame

Setup:

  1. GCC/G++: 9.2.0

  2. C++: C++17

Demo:

File Demo

#include <iostream>
#include <filesystem>
using namespace std;

namespace fs = std::filesystem;
    
int main(void) {    
    return 0;
}

I have tried the std::experimental variant to no success. How can I get C++17 & the <filesystem> API working?

Soln Update:

Thank you P Kramer, w/MSYS2 I was able to quickly come to solution.

Procedure:

  1. Get MSYS2 (msys2-x86_64-20210725.exe)
  2. Run the installer (@loc C:\Sw\msys64)
  3. pacman -Syu
  4. pacman -Su
  5. pacman -S --needed base-devel mingw-w64-x86_64-toolchain
  6. Check w/cmd (C:\Sw\msys64\mingw64\bin)
  7. gcc -v (GCC v10.3.0)
  8. Add to path (C:\Sw\msys64\mingw64\bin, C:\Sw\msys64\usr\bin)
  9. Restart Eclipse
  10. Demo compile to confirm C++17 (__cplusplus == 201703L)
  11. Use it!

Final Working Demo

J-Dizzle
  • 4,861
  • 4
  • 40
  • 50

1 Answers1

1

https://gcc.gnu.org/gcc-9/changes.html mentions incomplete filesystem implementation on windows. Goto compiler explorer and compile your sample with gcc 9.2 first. See here : https://godbolt.org/z/q9vTcernn This will indeed fail, if you change to latest gcc (for windows) everything compiles fine.

So the problem is the compiler version you are using.

Pepijn Kramer
  • 9,356
  • 2
  • 8
  • 19