Problem adding std::filesystem to CMake Project

后端 未结 4 615
余生分开走
余生分开走 2020-12-19 09:29

I am new to CMake projects and I want to use the file system library in my project. I am running Ubuntu 18.04 with GCC 8.2 and CMake 3.13. In order to achieve this I tried t

4条回答
  •  悲&欢浪女
    2020-12-19 10:17

    Gcc 8.2. comes with , so there is no need to investigate with regard to the availability. Next, option 1 is sufficient, but needs a fix:

    set(CMAKE_CXX_STANDARD 17) # no need to manually adjust the CXXFLAGS
    
    add_executable(yourExecutable yourSourceFile.cpp)
    
    target_link_libraries(yourExecutable stdc++fs)
    

    This should result in compiling the sources with -std=c++17 or -std=gnu++17 and adding -lstdc++fs when linking.

    Edit: Note that as @Ashkan has pointed out in the comments, setting CMAKE_CXX_STANDARD_REQUIRED to true results in an immediate error at configure time if C++17 isn't supported by the compiler, instead of a compilation error (due to the missing header) or at link time (due to the missing shared library). This might be desirable.

提交回复
热议问题