find_library does not find stdc++fs

I’m not sure why you’d be wanting to find this particular library. I’d expect the compiler would find the right one if you linked to stdc++fs. Either of the following should work:

target_link_libraries(SomeTarget PRIVATE stdc++fs)

To answer your question more directly, find_library() won’t be looking in any of the directories where you have a libstdc++fs.* file. You’d have to provide it with hints, but really I’d be looking to let the compiler provide it on its own with the default linker search path.

You would need to provide the logic that works out whether libstdc++fs.* needs to be linked rather than simply relying on whether you can find such a library or not. That probably means logic that only links it for specific version ranges of specific compilers. For example, cppreference.com contains the following note near the bottom of that page:

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.

1 Like