Problema:
Você quer compilar um executável usando GCC/G++ que usa funcionalidade de std::experimental::filesystem mas você obtém uma mensagem de erro como esta durante compilação / linking:
linker-error-stdc++fs.txt
test.cpp:(.text+0x33): undefined reference to `std::experimental::filesystem::v1::file_size(std::experimental::filesystem::v1::__cxx11::path const&)'
/tmp/ccSXeCVb.o: In function `std::experimental::filesystem::v1::__cxx11::path::path<char [9], std::experimental::filesystem::v1::__cxx11::path>(char const (&) [9])':
test.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2IA9_cS3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx114pathC5IA9_cS3_EERKT_]+0x73): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit statusSolução
Você precisa linkar a biblioteca stdc++fs, isto é, adicione -lstdc++fs ao seu comando g++.
Por exemplo, um comando funcional se parece com isso:
build-with-stdc++fs.sh
g++ -o myprogram main.cpp -lstdc++fs
Check out similar posts by category:
C/C++ Erros do GCC
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow