我需要使用(实验性) C++17
文件系统库编写程序,但在我的 Mac(macOS 10.12.03) 上的 clang
似乎没有包含文件系统标头。
由于我需要使用 C++17
,因此我不能使用 Boost
库之类的替代方案。
当我尝试编译仅包含文件系统和 iostream
的示例程序时(并写入 cout
)
#include <filesystem>
#include <iostream>
using namespace std;
int main(){
cout << "test" << endl;
}
我收到以下错误消息:
>clang test.cpp -std=c++1z
test.cpp:2:10: fatal error: 'filesystem' file not found
#include <filesystem>
^
1 error generated.
当我使用 GCC 6.3(通过自制软件安装)尝试相同的操作时,我得到:
>gcc-6 test.cpp -std=c++17
test.cpp:2:22: fatal error: filesystem: No such file or directory
#include <filesystem>
^
compilation terminated.
我还尝试使用实验/文件系统,而不是使用 gcc
编译,但似乎尝试为 iOS 编译导致另一个错误,这似乎与 iostream
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccd5QiVt.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccd5QiVt.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我的clang版本是:
>clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我很感谢任何有用的输入,因为到目前为止我找不到任何可以解决我的问题的东西(尽管我可能一直在寻找错误的术语)。
如果您需要更多信息,我很乐意提供,但我希望包含所有内容。
原文由 snoato 发布,翻译遵循 CC BY-SA 4.0 许可协议
Libc++ 是 OS X 上的 C++ 标准库,尚未将
<experimental/filesystem>
移动到<filesystem>
,因为规范不稳定。希望
<filesystem>
将成为 Clang 6.0 版本的一部分。 (我们错过了 5.0)