<i id='zWUzd'><tr id='zWUzd'><dt id='zWUzd'><q id='zWUzd'><span id='zWUzd'><b id='zWUzd'><form id='zWUzd'><ins id='zWUzd'></ins><ul id='zWUzd'></ul><sub id='zWUzd'></sub></form><legend id='zWUzd'></legend><bdo id='zWUzd'><pre id='zWUzd'><center id='zWUzd'></center></pre></bdo></b><th id='zWUzd'></th></span></q></dt></tr></i><div id='zWUzd'><tfoot id='zWUzd'></tfoot><dl id='zWUzd'><fieldset id='zWUzd'></fieldset></dl></div>
    1. <tfoot id='zWUzd'></tfoot>

    2. <legend id='zWUzd'><style id='zWUzd'><dir id='zWUzd'><q id='zWUzd'></q></dir></style></legend>
    3. <small id='zWUzd'></small><noframes id='zWUzd'>

      • <bdo id='zWUzd'></bdo><ul id='zWUzd'></ul>

        使用“实验/文件系统"构建项目;使用 cmake

        时间:2023-08-27
          <bdo id='tjy9p'></bdo><ul id='tjy9p'></ul>

                <tbody id='tjy9p'></tbody>
              <i id='tjy9p'><tr id='tjy9p'><dt id='tjy9p'><q id='tjy9p'><span id='tjy9p'><b id='tjy9p'><form id='tjy9p'><ins id='tjy9p'></ins><ul id='tjy9p'></ul><sub id='tjy9p'></sub></form><legend id='tjy9p'></legend><bdo id='tjy9p'><pre id='tjy9p'><center id='tjy9p'></center></pre></bdo></b><th id='tjy9p'></th></span></q></dt></tr></i><div id='tjy9p'><tfoot id='tjy9p'></tfoot><dl id='tjy9p'><fieldset id='tjy9p'></fieldset></dl></div>
                <legend id='tjy9p'><style id='tjy9p'><dir id='tjy9p'><q id='tjy9p'></q></dir></style></legend>
              • <small id='tjy9p'></small><noframes id='tjy9p'>

                <tfoot id='tjy9p'></tfoot>
                  本文介绍了使用“实验/文件系统"构建项目;使用 cmake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要在我的项目中添加一个实验/文件系统"头

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

                  #include <experimental/filesystem>
                  int main() {
                      auto path = std::experimental::filesystem::current_path();
                      return 0;
                  }
                  

                  所以我使用了 -lstdc++fs 标志并与 libstdc++fs.a 链接

                  So I used -lstdc++fs flag and linked with libstdc++fs.a

                  cmake_minimum_required(VERSION 3.7)
                  project(testcpp)
                  set(CMAKE_CXX_FLAGS "-std=c++14 -lstdc++fs" )
                  set(SOURCE_FILES main.cpp)
                  target_link_libraries(${PROJECT_NAME} /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++fs.a)
                  add_executable(testcpp ${SOURCE_FILES})
                  

                  但是,我有下一个错误:

                  However, I have next error:

                  CMakeLists.txt:9 处的 CMake 错误 (target_link_libraries):不能为不是由
                  构建的目标testcpp"指定链接库这个项目.

                  CMake Error at CMakeLists.txt:9 (target_link_libraries): Cannot specify link libraries for target "testcpp" which is not built by
                  this project.

                  但是如果我直接编译就可以了:

                  But if I compile directly, it`s OK:

                  g++-7 -std=c++14 -lstdc++fs  -c main.cpp -o main.o
                  g++-7 -o main main.o /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++fs.a
                  

                  我的错误在哪里?

                  推荐答案

                  只是 target_link_libraries() 调用必须在 add_executable() 调用之后.否则 testcpp 目标还不知道.CMake 按顺序解析所有内容.

                  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)
                  

                  这篇关于使用“实验/文件系统"构建项目;使用 cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:CMake 安装(子目录中的 TARGETS) 下一篇:在 CMakeList.txt 文件中包含 OpenSSL

                  相关文章

                  • <bdo id='pVUQd'></bdo><ul id='pVUQd'></ul>

                  1. <small id='pVUQd'></small><noframes id='pVUQd'>

                    1. <i id='pVUQd'><tr id='pVUQd'><dt id='pVUQd'><q id='pVUQd'><span id='pVUQd'><b id='pVUQd'><form id='pVUQd'><ins id='pVUQd'></ins><ul id='pVUQd'></ul><sub id='pVUQd'></sub></form><legend id='pVUQd'></legend><bdo id='pVUQd'><pre id='pVUQd'><center id='pVUQd'></center></pre></bdo></b><th id='pVUQd'></th></span></q></dt></tr></i><div id='pVUQd'><tfoot id='pVUQd'></tfoot><dl id='pVUQd'><fieldset id='pVUQd'></fieldset></dl></div>
                    2. <legend id='pVUQd'><style id='pVUQd'><dir id='pVUQd'><q id='pVUQd'></q></dir></style></legend><tfoot id='pVUQd'></tfoot>