1

I'm having troubles to link the filesystem library on C++. I have gcc 8.2.0:

#include<iostream>
#include <string>

#include <filesystem>
namespace fs = std::filesystem;

int main(int argc, char** argv){

    std::string path = "/";
    for (auto & p : fs::directory_iterator(path))
        std::cout << p << std::endl;

}

Here is my makefile:

CC= g++-8.2.0
CFLAGS= -Iheaders -std=c++17  -Wall

all: lsr 

lsr: lsr.o
  ${CC} ${CFLAGS} $? -o $@

%.o: %.cpp
  ${CC} ${CFLAGS} -c $<

clean:
  rm -f *.o lsr

gcc (Gentoo 8.2.0-r3 p1.4) 8.2.0

How can I fix it? :S

1 Answers1

1

Actually the filesystem library is not part of the standard library in gcc at this stage (same for clang and MSVC). The reason is the unstable ABI at this stage. You must add -lstdc++fs to your link stage as described in experimental::filesystem linker error (IIRC).

Matthieu Brucher
  • 21,634
  • 7
  • 38
  • 62