"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Why am I getting linker errors when using the experimental::filesystem library in GCC 6.0?

Why am I getting linker errors when using the experimental::filesystem library in GCC 6.0?

Posted on 2025-03-04
Browse:573

Why am I getting linker errors when using the experimental::filesystem library in GCC 6.0?

Linker Error with experimental::filesystem

When attempting to implement C 1z features using the experimental::filesystem library in GCC 6.0, users may encounter a linker error. The error message indicates an undefined reference to std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts().

Reason:

The Filesystem TS is not a part of C 1z but a separate specification. GCC's implementation of this library is available in C 11 mode.

Solution:

To resolve this issue, link with -lstdc fs. The libstdc fs.a library must come after objects that depend on it in the linker command.

Updates:

  • November 2017: GCC 8.x implemented the C 17 Filesystem library in the std::filesystem namespace. This library can be used with -std=gnu 17 or -std=c 17 and still requires linking with -lstdc fs.
  • January 2019: GCC 9 onwards allows the use of std::filesystem components without -lstdc fs.
  • April 2024: GCC 13.3 added std::experimental::filesystem symbols to -lstdc exp.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3