将C ++ 17文件系统与CMake链接的正确方法是什么? [英] What is the correct way to link C++17 filesystem with CMake?

查看:93
本文介绍了将C ++ 17文件系统与CMake链接的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到将我的CMake项目与gcc 8.3链接失败,无法链接std :: filesystem中的函数.gcc 9,clang 7或clang 8并非如此.

我发现了解决方案

到目前为止,似乎没有适当的解决方案.在CMake跟踪器上,与此主题有关的问题仍然有一个公开问题.>

有些人似乎正在使用查找模块,例如,这样您就可以使用以下代码:

  find_package(需要文件系统)add_executable(myapp myapp.cpp)target_link_libraries(myapp PRIVATE std :: filesystem) 

在我看来,这比更改 CMAKE_CXX_FLAGS 或直接链接到 stdc ++ fs 更为可取.

I noticed that linking my CMake project with gcc 8.3 fails to link functions from std::filesystem. This is not the case with gcc 9, clang 7 or clang 8.

I found solutions like this and this, but these hard-code the linking of stdc++fs, which is normally not what you want to do.

  • So what is the correct way to link such libraries?
  • Do I have to do a find_package? What would be the package I am looking for?

解决方案

It looks like there is no proper solution to this as of now. There still is an open issue on this subject on the CMake tracker.

Some seem to be using find modules like this one, which would allow you to use code like the following:

find_package(Filesystem REQUIRED)

add_executable(myapp myapp.cpp)
target_link_libraries(myapp PRIVATE std::filesystem)

In my opinion this is preferable to changing CMAKE_CXX_FLAGS or linking against stdc++fs directly.

这篇关于将C ++ 17文件系统与CMake链接的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆