【问题标题】:Linking to stdc++fs with C++20 still necessary when using filesystem?使用文件系统时仍然需要使用 C++20 链接到 stdc++fs?
【发布时间】:2020-06-19 10:45:16
【问题描述】:

我开始使用experimental::filesystem,当时它刚刚发布,我被建议使用target_link_libraries(MyTarget stdc++fs)CMake. 中链接stdc++fs省略额外的链接命令?

这个问题here 是三年前提出的,似乎认为stdc++fs 中的链接是必要的。

编辑:编译器版本是 g++-9 (Homebrew GCC 9.3.0_1) 9.3.0CMake 版本是 3.16。

非常感谢!

【问题讨论】:

  • 我猜这取决于你的编译器版本。从 cppreference,在文件系统库页面的最底部,您可以找到: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++fsen.cppreference.com/w/cpp/filesystem#Notes
  • 谢谢@NicoJ。如果你想把它写下来作为答案,我会接受的。基本上,您需要在这里提供一个检查编译器版本的 CMake 命令:stackoverflow.com/questions/14933172/…
  • 没问题,给你,谢谢

标签: c++ gcc std-filesystem


【解决方案1】:

从我的评论中删除:

我想这取决于您的编译器版本。从 cppreference,在文件系统库页面的最底部,您可以找到:

使用这个库可能需要额外的编译器/链接器选项。 GNU 9.1 之前的实现需要与 -lstdc++fs 和 LLVM 链接 LLVM 9.0 之前的实现需要使用 -lc++fs 链接

en.cppreference.com/w/cpp/filesystem#Notes

正如您所提到的,以下链接详细了解如何在 cmake 中检查编译器身份:How can I add a minimum compiler version requisite?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-28
    • 2015-12-02
    • 2017-12-17
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2016-03-08
    相关资源
    最近更新 更多