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

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

        使用 cmake 处理头文件依赖项

        Handling header files dependencies with cmake(使用 cmake 处理头文件依赖项)
            <bdo id='7BDJX'></bdo><ul id='7BDJX'></ul>
            <i id='7BDJX'><tr id='7BDJX'><dt id='7BDJX'><q id='7BDJX'><span id='7BDJX'><b id='7BDJX'><form id='7BDJX'><ins id='7BDJX'></ins><ul id='7BDJX'></ul><sub id='7BDJX'></sub></form><legend id='7BDJX'></legend><bdo id='7BDJX'><pre id='7BDJX'><center id='7BDJX'></center></pre></bdo></b><th id='7BDJX'></th></span></q></dt></tr></i><div id='7BDJX'><tfoot id='7BDJX'></tfoot><dl id='7BDJX'><fieldset id='7BDJX'></fieldset></dl></div>
          • <legend id='7BDJX'><style id='7BDJX'><dir id='7BDJX'><q id='7BDJX'></q></dir></style></legend>

                <tfoot id='7BDJX'></tfoot>
                  <tbody id='7BDJX'></tbody>

                <small id='7BDJX'></small><noframes id='7BDJX'>

                1. 本文介绍了使用 cmake 处理头文件依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在一个小型 C++ 项目中使用 CMake,到目前为止它工作得很好......只需一点点:x

                  I am using CMake on a small C++ project and so far it works great... with one twist :x

                  当我更改头文件时,它通常需要重新编译许多源文件(直接或间接包含它的那些),但是似乎 cmake 只检测一些源文件以被重新编译,导致损坏状态.我可以通过清除项目并从头开始重建来解决这个问题,但这绕过了使用 make 实用程序的目标:只重新编译需要的内容.

                  When I change a header file, it typically requires recompiling a number of sources files (those which include it, directly or indirectly), however it seems that cmake only detects some of the source files to be recompiled, leading to a corrupted state. I can work around this by wiping out the project and rebuilding from scratch, but this circumvents the goal of using a make utility: only recompiling what is needed.

                  因此,我想我做错了什么.

                  Therefore, I suppose I am doing something wrong.

                  我的项目非常简单:

                  • 所有资源所在的顶级目录,主要的 CMakeLists.txt 位于那里
                  • 一个包含"所有公共头文件所在的目录(在各个子目录中)
                  • 一个src"源文件的所有子目录所在的目录,src CMakeLists.txt 就在那里
                  • src"中每个子目录的 CMakeLists.txt目录

                  主目录有:

                  cmake_minimum_required(VERSION 2.8)
                  
                  project(FOO)
                  
                  set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
                  
                  # Compiler Options
                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++0x -Wall -Wextra -Werror")
                  
                  include_directories($(FOO_SOURCE_DIR)/include)
                  
                  add_subdirectory(src)
                  

                  src"目录:

                  add_subdirectory(sub1)
                  add_subdirectory(sub2)
                  add_subdirectory(sub3)
                  add_subdirectory(sub4)
                  
                  add_executable(foo main.cpp)
                  
                  target_link_libraries(foo sub1 sub2 sub3 sub4)
                  

                  其中 sub4 依赖于 sub3 依赖于 sub2 依赖于 sub1

                  Where sub4 depends on sub3 which depends on sub2 which depends on sub1

                  以及一个子目录(sub3)的例子:

                  And an example of a subdirectory (sub3):

                  set(SUB3_SRCS
                      File1.cpp
                      File2.cpp
                      File3.cpp
                      File4.cpp
                      File5.cpp
                      File6.cpp
                      )
                  
                  add_library(sub3 ${SUB3_SRCS})
                  
                  target_link_libraries(sub3 sub1 sub2)
                  

                  如果有人能指出我的错误,我会很高兴,在这里或在 CMake 上搜索没有产生任何结果,所以我想这很容易或者应该开箱即用...

                  I'd be glad if anyone could point my mistake to me, searching here or on CMake didn't yield anything so I guess it's very easy or should work out of the box...

                  (作为参考,我在 MSYS 上使用的是 cmake 2.8.2 版)

                  (for reference, I am using cmake version 2.8.2 on MSYS)

                  编辑:

                  感谢 Bill 的建议,我检查了 CMake 生成的 depend.make 文件,确实缺少(严重).下面是一个例子:

                  Thanks to Bill's suggestion I have checked the depend.make file generated by CMake, and it is indeed lacking (severely). Here is an example:

                  src/sub3/CMakeFiles/sub3.dir/File1.cpp.obj: ../src/sub3/File1.cpp
                  

                  是的,就是这样,根本没有引用任何包含:x

                  Yep, that's all, none of the includes were referenced at all :x

                  推荐答案

                  您应该查看二叉树中的 depend.make 文件.它将在 CMakeFiles/target.dir/depend.make 中.尝试找到其中一个缺少您认为应该具有的 .h 文件的文件.然后为 cmake 创建错误报告或通过电子邮件发送 cmake 邮件列表.

                  You should look at the depend.make files in your binary tree. It will be in CMakeFiles/target.dir/depend.make. Try to find one of those that is missing a .h file that you think it should have. Then create a bug report for cmake or email the cmake mailing list.

                  这篇关于使用 cmake 处理头文件依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                2. <tfoot id='eRQvF'></tfoot>
                      • <i id='eRQvF'><tr id='eRQvF'><dt id='eRQvF'><q id='eRQvF'><span id='eRQvF'><b id='eRQvF'><form id='eRQvF'><ins id='eRQvF'></ins><ul id='eRQvF'></ul><sub id='eRQvF'></sub></form><legend id='eRQvF'></legend><bdo id='eRQvF'><pre id='eRQvF'><center id='eRQvF'></center></pre></bdo></b><th id='eRQvF'></th></span></q></dt></tr></i><div id='eRQvF'><tfoot id='eRQvF'></tfoot><dl id='eRQvF'><fieldset id='eRQvF'></fieldset></dl></div>
                          <tbody id='eRQvF'></tbody>

                          <small id='eRQvF'></small><noframes id='eRQvF'>

                          • <bdo id='eRQvF'></bdo><ul id='eRQvF'></ul>
                            <legend id='eRQvF'><style id='eRQvF'><dir id='eRQvF'><q id='eRQvF'></q></dir></style></legend>