不同编译器中的std :: filesystem和std :: experimental :: filesystem问题 [英] std::filesystem and std::experimental::filesystem problem in different compilers

查看:248
本文介绍了不同编译器中的std :: filesystem和std :: experimental :: filesystem问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用std :: filesystem的库(仅供学习).它可以在MSVC上正常运行,但是默认情况下,Linux的LTS版本(如Ubuntu附带GCC 6.x)和官方存储库中的clang是3.8,它没有std :: filesystem,而我必须使用std :: experimental :: filesystem.如何解决此问题,以便可以支持GCC 6,GCC 8+(其中std :: filesystem工作),Clang 3.8,最新的Clang和MSVC?我正在使用CMAKE作为构建系统

I am writing a library (just for learning) which utilizes std::filesystem. It works fine on MSVC however by default LTS releases of Linux like Ubuntu ships with GCC 6.x and clang in the official repository is 3.8 which doesn't have std::filesystem instead I have to use std::experimental::filesystem. How may I workaround this problem so that I can support GCC 6, GCC 8+ (where std::filesystem works), Clang 3.8, latest Clang and MSVC? I am using CMAKE as my build system

推荐答案

有条件的编译可能会有所帮助:

Conditional compilation may help:

#if(defined(_MSC_VER) or (defined(__GNUC__) and (7 <= __GNUC_MAJOR__)))
using n_fs = ::std::filesystem;
#else
using n_fs = ::std::experimental::filesystem;    
#endif

这篇关于不同编译器中的std :: filesystem和std :: experimental :: filesystem问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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