【发布时间】:2019-02-27 12:48:45
【问题描述】:
很多人(例如1、2)都询问过如何让std::filesystem::directory_iterator 工作,但我在阅读这些内容后仍然遇到问题。
我正在尝试构建一个小型静态库。在将目录迭代器添加到一些源文件中后,我更新了我的 gcc,并添加了 -lstdc++fs 位,但似乎没有任何效果,因为我不断收到错误消息
fatal error: filesystem: No such file or directory
#include <filesystem>
如果我输入gcc --version,我会得到
gcc (Ubuntu 7.3.0-16ubuntu3) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
如果我输入 gcc-8 --version 我会得到
gcc-8 (Ubuntu 8.1.0-1ubuntu1) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
这是我编译所有内容的小 shell 脚本。我也尝试了其他一些变体。
EIGEN=/usr/include/eigen3
cd ./bin
for file in ../src/*cpp; do
g++ -std=c++11 -fPIC -c -I$EIGEN -I../include -O3 $file "-lstdc++fs"
done
ar crv libfoo.a *.o
cd ..
【问题讨论】:
-
你忘了告诉我们出了什么问题。
-
你如何尝试创建一个使用 libfoo.a 的实际可执行程序?
-
@JohnZwinck 抱歉。是这样的:致命错误:文件系统:没有这样的文件或目录
-
您是否尝试将
g++替换为g++-8? -
这不是链接器问题。是编译器找不到头文件。
标签: c++ c++11 gcc c++17 std-filesystem