找不到macOS Clang C ++ 17文件系统标头 [英] macOS Clang C++17 filesystem header not found

查看:468
本文介绍了找不到macOS Clang C ++ 17文件系统标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用(实验性的)C++17文件系统库编写程序,但是在我的 Mac(macOS 10.12.03)上的clang似乎没有包含文件系统标头.

I need to write a program using the (experimental) C++17 filesystem library but clang on my Mac (macOS 10.12.03) doesn't seem to have the filesystem header included.

由于需要使用C++17,因此无法使用Boost库之类的替代方法.

Since I'm required to use the C++17, I cannot use alternatives like the Boost library.

当我尝试编译仅包含文件系统和iostream(并写入cout)的示例程序时

When I try to compile a sample program that just includes filesystem and iostream (and writes to 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(通过自制程序安装)尝试相同操作时,我得到:

When I try the same using GCC 6.3 (installed via homebrew) I get:

>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

I also tried using experimental/filesystem instead which compiles using gcc but seems to try to compile for iOS leading to another error which seems to be related to 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版本是:

The version of my clang is:

>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

我很感谢任何有用的信息,因为到目前为止我还没有找到能解决我问题的东西(尽管我可能一直在寻找错误的术语).

I'm grateful for any helpful input since I couldn't find anything that solved my problem so far (although I might have been searching for the wrong terms).

如果您需要更多信息,我会很乐意提供,但希望包括所有内容.

If you need more information I'll gladly provide it but I hope to have included everything.

推荐答案

OS X上的C ++标准库Libc ++尚未将<experimental/filesystem>移至<filesystem>,因为该规范不稳定.

Libc++, which is the C++ standard library on OS X, has not moved <experimental/filesystem> to <filesystem> yet because the specification is not stable.

希望<filesystem>将成为Clang 6.0版本的一部分. (我们错过了5.0)

Hopefully <filesystem> will be a part of the Clang 6.0 release. (We missed 5.0)

这篇关于找不到macOS Clang C ++ 17文件系统标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆