3

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!

Hirek
  • 435
  • 3
  • 12
  • 3
    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` https://en.cppreference.com/w/cpp/filesystem#Notes – Nico J. Jun 19 '20 at 10:48
  • Thank you @NicoJ. if you want to write that up as the answer, I shall accept it. Basically, you need to provide a CMake command that checks compiler version a la here: https://stackoverflow.com/questions/14933172/how-can-i-add-a-minimum-compiler-version-requisite – Hirek Jun 19 '20 at 10:56

1 Answers1

4

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?

Nico J.
  • 167
  • 2
  • 10