Build project with “experimental/filesystem” using cmake

前端 未结 1 1946
醉酒成梦
醉酒成梦 2020-12-06 09:44

I need to add a \"experimental/filesystem\" header to my project

#include 
int main() {
    auto path = std::experimental::fi         


        
相关标签:
1条回答
  • 2020-12-06 10:11

    It's just that the target_link_libraries() call has to come after the add_executable() call. Otherwise the testcpp target is not known yet. CMake parses everything sequential.

    So just for completeness, here is a working version of your example I've tested:

    cmake_minimum_required(VERSION 3.7)
    
    project(testcpp)
    
    set(CMAKE_CXX_STANDARD 14)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    # NOTE: The following would add library with absolute path
    #       Which is bad for your projects cross-platform capabilities
    #       Just let the linker search for it
    #add_library(stdc++fs UNKNOWN IMPORTED)
    #set_property(TARGET stdc++fs PROPERTY IMPORTED_LOCATION "/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++fs.a")
    
    set(SOURCE_FILES main.cpp)
    add_executable(testcpp ${SOURCE_FILES})
    target_link_libraries(${PROJECT_NAME} stdc++fs)
    
    0 讨论(0)
提交回复
热议问题