How to fix C++ link errors such as "undefined reference to std::filesystem::..."

Problem:

While compiling/linking your C++ project using GCC or Clang you see error messages such as

Solution

You need to link the stdc++fs library which comes with your compiler and implements the std::filesystem functionality.

Link it by adding -lstdc++fs to your compiler flags.


Check out similar posts by category: C/C++, GCC Errors