问题描述
我注意到将我的CMake项目与gcc 8.3链接失败,无法链接std :: filesystem中的函数.gcc 9,clang 7或clang 8并非如此.
我发现了此和,但是这些硬编码了 stdc ++ fs
的链接,这通常不是您想要的.
- 那么链接此类库的正确方法是什么?
- 我必须做一个
find_package
吗?我要寻找的包裹是什么?
到目前为止,似乎没有适当的解决方案.在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链接的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!