Home  >  Article  >  Backend Development  >  How to Resolve Linker Errors When Using `experimental::filesystem` in GCC?

How to Resolve Linker Errors When Using `experimental::filesystem` in GCC?

Linda Hamilton
Linda HamiltonOriginal
2024-11-15 14:07:02609browse

How to Resolve Linker Errors When Using  `experimental::filesystem` in GCC?

Fixing Linker Error for experimental::filesystem

When attempting to utilize the latest C 1z features with GCC 6.0, particularly with the experimental::filesystem library, you may encounter a linker error like this:

undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'

The Difference between Filesystem TS and C 1z

It's important to note that the Filesystem TS (Technical Specification) is not part of the C 1z (now C 20) standard. Hence, the error is not related to C 1z support but to linking with the appropriate library.

Linking with the Filesystem TS Library

To resolve the issue, link your code with the static library -lstdc fs. This will provide the necessary implementation for the experimental::filesystem features. Remember to place it after any objects that depend on it in the linker command.

Updates on Filesystem Support in GCC

November 2017:
GCC 8.x introduces a C 17-compliant Filesystem library under the namespace std::filesystem. It requires both -std=gnu 17 and -lstdc fs for usage.

January 2019:
GCC 9 allows the use of std::filesystem components without -lstdc fs.

April 2024:
GCC 13.3 presents experimental::filesystem symbols in -lstdc exp, alongside other experimental definitions.

The above is the detailed content of How to Resolve Linker Errors When Using `experimental::filesystem` in GCC?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn