问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/58545562/what-is-the-correct-way-to-link-c17-filesystem-with-cmake