无法链接文件系统库C++



我在C++上链接文件系统库时遇到问题。我有 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;
}

这是我的制作文件:

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

我该如何解决? :S

实际上文件系统库在这个阶段不是 gcc 标准库的一部分(对于 clang 和 MSVC 也是如此(。原因是现阶段的ABI不稳定。 必须按照实验性::文件系统链接器错误 (IIRC( 中所述将-lstdc++fs添加到链接阶段。

最新更新