在包含< experimental / filesystem>之后,尚未声明'std :: filesystem'。 [英] 'std::filesystem' has not been declared after including <experimental/filesystem>

查看:987
本文介绍了在包含< experimental / filesystem>之后,尚未声明'std :: filesystem'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了有关c ++ 17下文件系统链接的很多问题,但仍然无法成功建立链接。我的 main.cpp 文件如下。

I have checked a lot of issues about the link of filesystem under c++17 and I still cannot make the link successfully. My main.cpp file is as the following.

#include <experimental/filesystem>


int main(int argc, char** argv)
{
    std::string imageDirectory = "./image";;
    std::vector<std::string> imagePath;

    for (const auto& entry: std::filesystem::directory_iterator(imageDirectory))
    {
        imagePath.push_back(entry.path());
        std::cout << entry.path() << std::endl;
    }

    return 0;
}

我的 CMakeLists.txt 如下所示。

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)

project(visual_hull LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
add_library(dataIO
        STATIC
            dataIO.hpp
            dataIO.cpp)

find_package(OpenCV REQUIRED core highgui imgproc)

target_link_libraries(dataIO ${OpenCV_LIBS})

add_executable(visual_hull main.cpp)

target_link_libraries(visual_hull PUBLIC dataIO
                                         stdc++fs)

错误如下。

/home/SENSETIME/zhangshunkang/Downloads/programming/c++/visual_hull/main.cpp: In function ‘int main(int, char**)’:
/home/SENSETIME/zhangshunkang/Downloads/programming/c++/visual_hull/main.cpp:15:31: error: ‘std::filesystem’ has not been declared
  for (const auto& entry: std::filesystem::directory_iterator(imageDirectory))
                               ^
CMakeFiles/visual_hull.dir/build.make:62: recipe for target 'CMakeFiles/visual_hull.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/visual_hull.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/visual_hull.dir/all' failed
make[1]: *** [CMakeFiles/visual_hull.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2


推荐答案

您使用 std :: filesystem :: directory_iterator std :: filesystem :: directory_iterator 和整个命名空间 std :: filesystem 在标头<$ c $中声明c>< filesystem> 。

You use std::filesystem::directory_iterator. std::filesystem::directory_iterator and the entire namespace std::filesystem are declared in the header <filesystem>.

您尚未包含标头< filesystem> 。相反,您包括了< experimental / filesystem> 。此标头未声明 std :: filesystem :: directory_iterator 。相反,它声明 std :: experimental :: filesystem :: directory_iterator

You haven't included the header <filesystem>. Instead, you've included <experimental/filesystem>. This header does not declare std::filesystem::directory_iterator. Instead, it declares std::experimental::filesystem::directory_iterator.

您可以始终使用任一标准文件系统库,或技术规范中的实验性文件系统库,但不得将它们混合在一起。如果您的目标是C ++ 17,则应使用< filesystem>

You can consistently use either the standard filesystem library, or the experimental filesystem library from the technical specification, but you must not mix them together. If you're targeting C++17, then you should use <filesystem>.


我将收到文件系统错误:没有这样的文件或目录

I will get the error that filesystem: No such file or directory

理想的解决方案是将编译器升级到具有对C ++ 17的非实验支持的版本。否则,请使用实验性TS或Boost。

The ideal solution is to upgrade your compiler to a version that has non-experimental support for C++17. Otherwise use the experimental TS or Boost.

这篇关于在包含&lt; experimental / filesystem&gt;之后,尚未声明'std :: filesystem'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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