首頁 > 後端開發 > C++ > 在 GCC 中使用 `experimental::filesystem` 時如何解決連結器錯誤?

在 GCC 中使用 `experimental::filesystem` 時如何解決連結器錯誤?

Linda Hamilton
發布: 2024-11-15 14:07:02
原創
700 人瀏覽過

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.

以上是在 GCC 中使用 `experimental::filesystem` 時如何解決連結器錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板