【发布时间】:2017-07-26 18:52:21
【问题描述】:
我需要使用(实验性)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.
我也尝试使用experimental/filesystem 代替它使用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
感谢您提供任何有用的意见,因为到目前为止我找不到任何可以解决我的问题的东西(尽管我可能一直在寻找错误的术语)。
如果您需要更多信息,我很乐意提供,但我希望包含所有内容。
【问题讨论】:
-
如果作业有这个要求,也许老师应该告诉你如何实际实现这个(编译器和编译器标志)?
-
好吧,他只使用 Linux,所以他不知道如何在 mac 上操作...
-
@DeiDei Libc++ (Clang) 不会在 4.0 中发布
<filesystem>。 -
如果你真的必须用 C++17 来做这件事,那么要么在你的 Mac 上安装一个 Linux VM,要么看看像homebrew 这样的东西是否支持 C++17 + 文件系统。
-
对于gcc案例this may help