Home > Backend Development > C++ > body text

Why am I getting a linker error when using `std::experimental::filesystem` in GCC 6.0?

DDD
Release: 2024-11-17 13:13:02
Original
299 people have browsed it

Why am I getting a linker error when using `std::experimental::filesystem` in GCC 6.0?

linker error for experimental::filesystem

When attempting to utilize the novel c 1z features in the current development version of gcc 6.0, an example program encounters a linker error:

#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;

int main()
{
    fs::path p1 = "/home/pete/checkit";

    std::cout << "p1 = " << p1 << std::endl;
}
Copy after login

Results in the following error:

/opt/linux-gnu_6-20151011/bin/g++ --std=c++1z main.cpp -O2 -g -o go
/tmp/ccaGzqFO.o: In function \`std::experimental::filesystem::v1::__cxx11::path::path(char const (&) [36])':
/opt/linux-gnu_6-20151011/include/c++/6.0.0/experimental/bits/fs_path.h:167: undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
Copy after login

Resolution

The Filesystem TS is distinct from C 1z support and is not part of the C 1z working draft. The linking issue can be resolved by linking with -lstdc fs to access the library.

Updates

  • In GCC 8.x, the C 17 Filesystem implementation is also available in namespace std::filesystem with -std=gnu 17 or -std=c 17, but requires linking to -lstdc fs.
  • In GCC 9, the C 17 filesystem components can be used without -lstdc fs.
  • In GCC 13.3, the std::experimental::filesystem symbols are also available in -lstdc exp.

The above is the detailed content of Why am I getting a linker error when using `std::experimental::filesystem` in GCC 6.0?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template