【发布时间】:2019-09-16 19:43:46
【问题描述】:
考虑这个最小的例子:
#include <filesystem>
#include <iostream>
int main()
{
std::cout << std::filesystem::current_path() << '\n';
}
它在 GCC 9.2 中按预期工作,但 Clang 8.0.1 拒绝编译 <filesystem> 标头(来自 GCC 9.2 的 libstdc++):
# clang++ 1.cpp -std=c++17
In file included from 1.cpp:1:
In file included from Z:\Lander\msys2\mingw64\include\c++\9.2.0\filesystem:37:
Z:\Lander\msys2\mingw64\include\c++\9.2.0\bits/fs_path.h:636:31: error: invalid use of incomplete
type 'std::filesystem::__cxx11::filesystem_error'
_GLIBCXX_THROW_OR_ABORT(filesystem_error(
^~~~~~~~~~~~~~~~~
Z:\Lander\msys2\mingw64\include\c++\9.2.0\x86_64-w64-mingw32\bits/c++config.h:177:49: note: expanded
from macro '_GLIBCXX_THROW_OR_ABORT'
# define _GLIBCXX_THROW_OR_ABORT(_EXC) (throw (_EXC))
^~~~
Z:\Lander\msys2\mingw64\include\c++\9.2.0\bits/fs_fwd.h:61:9: note: forward declaration of
'std::filesystem::__cxx11::filesystem_error'
class filesystem_error;
^
1 error generated.
是 Clang 错误还是 libstdc++ 错误?
我在 MSYS2 错误跟踪器上找到了this bug report,但那里没有有用的信息。
在我们等待官方修复的同时,有没有办法修补 <filesystem> 标头以消除此错误?
我在 Windows 上。我正在使用 MSYS2 软件包中提供的最新 GCC 和 Clang。
GCC 标识为:
# g++ --version
g++.exe (Rev2, Built by MSYS2 project) 9.2.0
Copyright (C) 2019 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.
Clang 标识为:
# clang++ --version
clang version 8.0.1 (tags/RELEASE_801/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: Z:\Lander\msys2\mingw64\bin
Clang 使用这个 GCC 附带的 libstdc++。
【问题讨论】:
-
我不会说这是任何一个错误。标准库被认为是实现的一部分,gcc 没有义务使其库实现符合其他(非 gcc)编译器。
-
至于实用的解决方案,你为什么不用LLVM的标准库?
-
@SergeyA “标准库被认为是实现的一部分” 没错,但 Clang 通常与 libstdc++(甚至与 MSVC 的标准库)兼容。即使它在技术上不是一个错误,我认为它会在任何一方得到修复。 “你为什么不使用 LLVM 的标准库” 我不确定 libc++ 是否适用于 Windows。上次我尝试过(几个月前),它无法使用。
-
对不起,也许这很愚蠢,您是否尝试在编译命令中使用 -lstdc++fs?
-
@Boki 我认为它不会起作用。
-lstdc++fs影响链接,但我收到编译错误(链接甚至没有开始)。
标签: c++ clang libstdc++ std-filesystem