When compiling code examples from a textbook, I run into a compilation error: ld: library not found for -lstdc fs
. What does this error mean and how can I get around it?
% make filesystem
Consolidate compiler generated dependencies of target filesystem
[100%] Linking CXX executable filesystem
ld: library not found for -lstdc fs
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [chapter_17/filesystem] Error 1
make[2]: *** [chapter_17/CMakeFiles/filesystem.dir/all] Error 2
make[1]: *** [chapter_17/CMakeFiles/filesystem.dir/rule] Error 2
make: *** [filesystem] Error 2
CodePudding user response:
In short, linking stdc fs
is not longer necessary as it has been incorporated into the base library.
When the textbook was first written the C libraries didn't officially support filesystem yet, so they would require a secondary library called stdc fs
. This was a libstdc
specific library that imported the C 17 features that weren't in the official library yet.
Now, both GCC's libstdc
and Clang's libc
include it in their base library, and the stdc fs
library got dropped.
You can drop the linking to that library without any problems; it patched a problem in compiler support that's no longer relevant