Facundo Curti
Facundo Curti

Reputation: 153

Cant link filesystem library con C++

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

Upvotes: 1

Views: 774

Answers (1)

Matthieu Brucher
Matthieu Brucher

Reputation: 22023

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).

Upvotes: 1

Related Questions