https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91067
Bug ID: 91067 Summary: Clang compiler can't link executable if std::filesystem::directory_iterator is encountered Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: boris.staletic at gmail dot com Target Milestone: --- When compiling with clang, a code that contains an object of the type std::filesystem::directory_iterator produces the following linker error: /usr/sbin/ld: /tmp/bar-5627f7.o: in function `std::filesystem::__cxx11::directory_iterator::directory_iterator()': bar.cpp:(.text._ZNSt10filesystem7__cxx1118directory_iteratorC2Ev[_ZNSt10filesystem7__cxx1118directory_iteratorC2Ev]+0x1): undefined reference to `std::__shared_ptr<std::filesystem::__cxx11::_Dir, (__gnu_cxx::_Lock_policy)2>::__shared_ptr()' clang-8: error: linker command failed with exit code 1 (use -v to see invocation) The minimal reproducer had to be preprocessed with clang to avoid errors like "/usr/include/c++/9.1.0/bits/stl_function.h:475:6: error: use of undeclared identifier '__builtin_is_constant_evaluated'" when compiling. For this reason I will attach a non-preprocessed file too. Clang version - 8.0.0 (tags/RELEASE_800/final) Clang command line - clang++ -std=c++17 bar.ii -O1 -lstdc++fs GCC version - 9.1.0 Target - x86_64-pc-linux-gnu GCC compile time configuration options: COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/9.1.0/lto-wrapper Configured with: /build/gcc/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp --enable-cet=auto Thread model: posix Additional note: Changing the optimization level can avoid the linker error.