Команда работала для Cmake.

от вопрос уже есть ответ здесь:

Ошибки связи с использованием элементов <filesystem> в C ++ 17 2 ответа

У меня проблема с моим C ++, созданным при попытке использоватьstd::filesystem::directory_iterator из стандарта C ++ 17.

Вот код:

std::vector<std::string> IO::getDirectoryList(std::filesystem::path& dirPath)
{
  std::vector<std::string> files;
  for (auto& file : std::filesystem::directory_iterator("."))
  {
    files.push_back(file.path());
  }
  return files;
}

Я получаю следующую ошибку:

> In function
> `StoryTime::IO::getDirectoryList(std::filesystem::__cxx11::path&)':
> IO.cpp:(.text+0x122): undefined reference to
> `std::filesystem::__cxx11::directory_iterator::operator*() const'
> IO.cpp:(.text+0x178): undefined reference to
> `std::filesystem::__cxx11::directory_iterator::operator++()'
> CMakeFiles/StoryTime.dir/IO.cpp.o: In function
> `std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
> const&)':
> IO.cpp:(.text._ZNSt10filesystem7__cxx1118directory_iteratorC2ERKNS0_4pathE[_ZNSt10filesystem7__cxx1118directory_iteratorC5ERKNS0_4pathE]+0x26):
> undefined reference to
> `std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path
> const&, std::filesystem::directory_options, std::error_code*)'
> CMakeFiles/StoryTime.dir/IO.cpp.o: In function
> `std::filesystem::__cxx11::path::path<char [2],
> std::filesystem::__cxx11::path>(char const (&) [2],
> std::filesystem::__cxx11::path::format)':
> IO.cpp:(.text._ZNSt10filesystem7__cxx114pathC2IA2_cS1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5IA2_cS1_EERKT_NS1_6formatE]+0x6d):
> undefined reference to
> `std::filesystem::__cxx11::path::_M_split_cmpts()' collect2: error: ld
> returned 1 exit status

Это использует CMake-3.8 с gcc-8 / g ++ - 8, который должен иметь хорошую поддержкуstd::filesystem.

Это вывод c ++ -v:

> Using built-in specs. COLLECT_GCC=c++
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
> OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target:
> x86_64-linux-gnu Configured with: ../src/configure -v
> --with-pkgversion='Ubuntu 8.1.0-5ubuntu1~16.04' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 8.1.0 (Ubuntu 8.1.0-5ubuntu1~16.04)

И CMake находит правильный компилятор:

> -- The C compiler identification is GNU 8.1.0
> -- The CXX compiler identification is GNU 8.1.0
> -- Check for working C compiler: /usr/bin/cc
> -- Check for working C compiler: /usr/bin/cc -- works
> -- Detecting C compiler ABI info
> -- Detecting C compiler ABI info - done
> -- Detecting C compile features
> -- Detecting C compile features - done
> -- Check for working CXX compiler: /usr/bin/c++
> -- Check for working CXX compiler: /usr/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Configuring done
> -- Generating done
> -- Build files have been written to:

Обратите внимание, что простая компиляция с заголовком файловой системы работает, а также с использованием кодаstd::filesystem::path, Но как только я пытаюсь использоватьstd::filesystem::directory_iterator появляется проблема с компоновщиком.

Любая помощь приветствуется.

Ответы на вопрос(1)

Ваш ответ на вопрос