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

      <legend id='OBzZb'><style id='OBzZb'><dir id='OBzZb'><q id='OBzZb'></q></dir></style></legend>

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

        <tfoot id='OBzZb'></tfoot>
        • <bdo id='OBzZb'></bdo><ul id='OBzZb'></ul>
      2. 制作配方以防止重建非依赖目标

        Make recipe to prevent rebuilding of non-dependent targets(制作配方以防止重建非依赖目标)

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

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

                <bdo id='cvIiQ'></bdo><ul id='cvIiQ'></ul>

                    <tbody id='cvIiQ'></tbody>

                • 本文介绍了制作配方以防止重建非依赖目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下项目目录结构:

                  I have the following project directory structure:

                  Prog
                  /include
                  /include/dir1
                  /include/dir2
                  /src
                  /src/dir1
                  /src/dir2
                  

                  App1 依赖于 mod1 和 mod2,而 App2 只依赖于 mod1.

                  App1 depends on mod1 and mod2 where as App2 depends only on mod1.

                  使用下面表示的 makefile,模块和应用程序都可以正确构建 - 但是,如果我对 mod2 进行更改,然后执行全部构建",即使 App2 没有依赖项,它也会重新构建.

                  With the makefile denoted below the modules and apps all build correctly - however if I make a change to mod2 and then do a 'make all', App2 gets rebuilt even though it doesn't have a dependency.

                  这样做的原因是,传递到目标构建配方的 OBJ 是所有 OBJ,而不仅仅是当前目标需要的特定 OBJ.

                  The reason for this is because OBJ being passed into the target build recipe is all of the OBJs and not just the specific ones that the current target needs.

                  我想知道可以对 makefile 进行哪些更改以仅将依赖对象传递给正在构建的当前目标.

                  I was wondering what change to the makefile can be made to only pass the dependent objects to the current target that's being built.

                  生成文件:

                  CC        := g++
                  LD        := g++
                  
                  TARGETS   := app1 app2
                  MODULES   := mod1 mod2
                  INC_DIR   := $(addprefix include/,$(MODULES))
                  SRC_DIR   := $(addprefix src/,$(MODULES))
                  BUILD_DIR := $(addprefix build/,$(MODULES))
                  
                  SRC       := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
                  OBJ       := $(patsubst src/%.cpp,build/%.o,$(SRC))
                  INCLUDES  := -Iinclude $(addprefix -I,$(INC_DIR))
                  
                  vpath %.cpp $(SRC_DIR)
                  
                  define make-goal
                  $1/%.o: %.cpp
                     $(CC) $(INCLUDES) -c $$< -o $$@
                  endef
                  
                  .PHONY: all checkdirs clean
                  
                  all: checkdirs $(TARGETS)
                  
                  $(TARGETS) : %: $(OBJ)
                     $(CC) $(INCLUDES) -o build/$@ src/$@.cpp $^
                  
                  checkdirs: $(BUILD_DIR)
                  
                  $(BUILD_DIR):
                     @mkdir -p $@
                  

                  makefile 已从以下答案中重新调整用途:https://stackoverflow.com/a/2484343

                  The makefile has been repurposed from the following answer: https://stackoverflow.com/a/2484343

                  推荐答案

                  在虚假的全部"目标中列出了三个目标.

                  there are three targets listed in the phony 'all' target.

                  每一个都应该有一个单独的规则列出,而不是将两个目标app1"和app2"混为一谈.

                  Each of those should have a separate rule listed, rather than lumping two of the targets 'app1' and 'app2' together.

                  注意:任何常见的文件更改/编译都会导致两个目标都被重新创建.

                  Note: any common file changes/compiles will result in both targets being re-created.

                  将SRC"分解为 SRC_APP1 SRC_APP2,然后在 app1 和 app2 目标中使用适当的 SRC_APPx 宏.

                  break the 'SRC' into SRC_APP1 SRC_APP2 then use the appropriate SRC_APPx macro in each of the app1 and app2 targets.

                  对 'OBJ' 宏和 'INCLUDES' 宏使用类似的分隔

                  use similar separation for the 'OBJ' macro and the 'INCLUDES' macro

                  不要使用foreach"规则,因为它要求构建所有目标

                  Do not use the 'foreach' rules as that is asking for all the targets to be built

                  还有其他几个细节需要解决,但以上应该为您指明了正确的方向.

                  there are several other details that need addressing, but the above should point you in the right direction.

                  应该有很大帮助的一件事.

                  One thing that should greatly help.

                  将 app1 和 app2 的目标文件放在不同的控制器中,并让 makefile 在每个 appx 的适当目录中查找

                  Have the object files for app1 and app2 placed in separate directors and have the makefile look in the appropriate directory for each appx

                  这篇关于制作配方以防止重建非依赖目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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?)

                    <tfoot id='IIG1N'></tfoot>

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

                      <tbody id='IIG1N'></tbody>

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

                            <legend id='IIG1N'><style id='IIG1N'><dir id='IIG1N'><q id='IIG1N'></q></dir></style></legend>