编译filesystem时出现错误fatal error: filesystem: No such file or directory;filesystem没有那个文件或目录

编译filesystem时出现错误fatal error: filesystem: No such file or directory

据说gcc8可以解决,但gcc --version发现我的版本是7.5

解决方法如下:

1.头文件修改

#include <filesystem>改为#include <experimental/filesystem>

#include <experimental/filesystem>

如果编译出现error: 'std::filesystem' has not been declared,看步骤2

2.命名空间修改

namespace fs = std::filesystem改为namespace fs = std::experimental::filesystem;

namespace fs = std::experimental::filesystem;

3.cmakefile修改|编译添加依赖库stdc++fs

target_link_libraries(xxx_xx

    ${catkin_LIBRARIES}

    stdc++fs   --添加

)

target_link_libraries(xxx_xx
    ${catkin_LIBRARIES}
    stdc++fs
)

再编译后解决。

使用如下:

fs::path p(obj_path);
if (!fs::exists(p)) {
    std::cout << obj_path << " not exists!" << std::endl;
    bool c_ok = fs::create_directories(obj_path);
    if (c_ok) std::cout << obj_path << " created!" << std::endl;
}

参考1:ubuntu(21):fatal error: filesystem: No such file or directory,fatal error: filesystem: 没有那个文件或目录-CSDN博客参考2:fatal error: filesystem: 没有那个文件或目录_fatal error: filesystem: no such file or directory-CSDN博客

  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值