Reputation: 473
I began using experimental::filesystem
when it had just come out and I was advised to link in stdc++fs
using target_link_libraries(MyTarget stdc++fs)
in CMake.
My programme builds either way but may I be breaking something/ doing something unnecessary if I leave out the extra link command?
This question here was asked three years ago and seems to assume that linking in stdc++fs
was necessary.
Edit: compiler version is g++-9 (Homebrew GCC 9.3.0_1) 9.3.0
and CMake
version is 3.16.
Many thanks!
Upvotes: 6
Views: 9218
Reputation: 317
Lifted from my comment:
I guess it depends on your compiler version. From cppreference, At the very bottom of the File System Library page, you can find:
Using this library may require additional compiler/linker options. GNU implementation prior to 9.1 requires linking with -lstdc++fs and LLVM implementation prior to LLVM 9.0 requires linking with -lc++fs
en.cppreference.com/w/cpp/filesystem#Notes
As you mentioned, the following link get more in details about how to check compiler identity in cmake: How can I add a minimum compiler version requisite?
Upvotes: 7