带有c 17的`filesystem`在我的mac os x high sierra上不起作用
我正在学习本教程:
http://www.bfilipek.com/2017/08/cpp17-details-filesystem.html 检查新的c文件系统功能.但是我无法在我的机器上编译最小的例子: #include <string> #include <iostream> #include <filesystem> namespace fs = std::filesystem; int main() { std::string path = "/"; for (auto & p : fs::directory_iterator(path)) std::cout << p << std::endl; } 我正在尝试编译它时使用XCode,CLion和命令行,但没有任何作用,我有版本9.3(9E145)与(看似正确的)项目设置,没有一个工作: 这是我对CLion的CMakeLists.txt文件: cmake_minimum_required(VERSION 3.8) project(FileSystem2) set(CMAKE_CXX_STANDARD 17) add_executable(FileSystem2 main.cpp) 这是>的输出. gxx –version: 不过这是我从IDE获得的输出: 我做错了什么,我认为我的编译器应该支持c 17? 编辑 根据Owen Morgan的回答我已经安装了clang(实际的安装命令是brew install llvm),但它现在抱怨缺少string.h.有什么想法吗? 解决方法
Xcode附带的编译器支持C 17语言功能,但不支持C 17标准库功能.查看屏幕截图,您将看到标准库支持达到C 11,Apple尚未发布具有stdlib支持C 14或C 17的clang版本.
但是希望不会丢失!您可以从brew包管理器下载最新版本的clang. brew install clang 然后,您可以通过将cmake编译器标志设置为自定义brew版本然后运行它来进行编译. 以下是如何执行此操作的链接:http://antonmenshov.com/2017/09/09/clang-openmp-setup-in-xcode/ 编辑: 安装llvm后,您需要将llvm路径链接到当前shell.我有一个shell脚本,我在工作中使用它来正确设置.希望这可以帮助. #!/bin/bash brew update brew install --with-toolchain llvm # llvm but with all the headers xcode-select --install # installs additional headers that you might be mimssing. echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.bash_profile # exports the custom llvm path into the shell sudo ln -s /usr/local/opt/llvm/bin/clang++ /usr/local/bin/clang++-brew # optional but I like to have a symlink set. 编辑2: Clang 6.0没有< filesystem>包含在macOS上,但是你可以获得< experimental / filesystem>,并链接-lc实验,并使用std :: experimental :: filesystem而不是std :: filesystem. 最后的命令行调用: Owen $/usr/local/Cellar/llvm/6.0.0/bin/clang fs.cpp -std = c 1z -L /usr/local/Cellar/llvm/6.0.0/lib/ -lc experimental (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |