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; }
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
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
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!