Search code examples
c++gccg++gnu

Can't use std::filesystem in code built with make and g++


I have some problems with building my c++ app with make. I have such c++ code:

#include <string>
#include <iostream>
#include <filesystem>

using namespace std;

namespace fs = std::filesystem;

int main()
{
    auto iter = fs::directory_iterator(fs::current_path());
    while(iter._At_end())
    {
        cout << iter->path() << endl;
    }
    return 0;
}

I am trying to compile object file with command: g++-9 -std=c++17 -Wall -Wextra -pthread -lstdc++fs -c -o main.o main.cpp But I have this error:

main.cpp:12:16: error: ‘class std::filesystem::__cxx11::directory_iterator’ has no member named ‘_At_end’
   12 |     while(iter._At_end())
      |                ^~~~~~~

So, I cant use members of classes of std::filesystem namespace but if I wanna use only class(for example std::filesystem::path), so everything is ok.

Versions of soft:

g++-9 (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
GNU Make 4.2.1

Hope you'll help me.


Solution

  • Just don't use _At_end() and everything will be ok.