- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个 C++ 生成文件项目。它非常适合非平行建筑。对于并行构建,它的工作效率为 99%...我唯一的问题是我无法让我的最终可执行链接行最后运行(它必须是最后发生的事情)。
我有一些限制:我不想在我的链接线上有任何 PHONY 依赖项,因为这会导致它每次都重新链接。 IE。一旦构建了我的目标,当我重新构建它时不应重新链接。
这是(稍微做作的)最小示例。请不要试图挑剔它,它真的在这里只是为了显示问题,它不是真实的,但我正在显示的问题是。您应该能够运行它并看到与我相同的问题。
# Set the default goal to build.
.DEFAULT_GOAL = build
#pretend subdirs (these don't really exist but it does not matter so long as they always try to be built)
MAKE_SUB_DIRS = 1 2 3
#pretend shared objects that are created by the pretend makefile sub directories (above)
OUTPUTS = out1.so out2.so out3.so
# Top level build goal - depends on all of the subdir makes and the target.out
.PHONY: build
build: $(MAKE_SUB_DIRS) target.out
@echo build finished
# Takes 1 second to build each of these pretend sub make directories. PHONY so always runs
.PHONY: $(MAKE_SUB_DIRS)
$(MAKE_SUB_DIRS):
@if [ ! -f out$@.so ] ; then echo making $@... ; sleep 1 ; echo a > out$@.so ; fi
# The main target, pretending that it needs out1,2 and 3 to link
# Should only run when target.out does not exist
# No PHONY deps allowed here
target.out:
@echo linking $@...
@ls $(OUTPUTS) > /dev/null
@cat $(OUTPUTS) > target.out
# Clean for convinience
clean:
@rm -rf *.so target.out
现在,我真的不在乎 make
是否正常工作,我想要的是 make -j
正常工作。这是我尝试运行它:
admin@osboxes:~/sandbox$ make clean
admin@osboxes:~/sandbox$
admin@osboxes:~/sandbox$ make -j - 1st attempt
making 1...
making 2...
linking target.out...
making 3...
ls: cannot access 'out1.so': No such file or directory
ls: cannot access 'out2.so': No such file or directory
ls: cannot access 'out3.so': No such file or directory
makefile:24: recipe for target 'target.out' failed
make: *** [target.out] Error 2
make: *** Waiting for unfinished jobs....
admin@osboxes:~/sandbox$
admin@osboxes:~/sandbox$ make -j - 2nd attempt
linking target.out...
build finished
admin@osboxes:~/sandbox$
admin@osboxes:~/sandbox$ make -j - 3rd attempt
build finished
admin@osboxes:~/sandbox$
所以我突出显示了我运行它的三个尝试。
making x...
都需要 1 秒,而 linking
几乎是即时的,所以我们看到了我的错误。但是,所有三个“库”都已正确构建。所以你可以看到所有的步骤都在那里,这只是对它们进行排序的问题。我希望 make sub dirs 1, 2, 3
以任何顺序并行构建,然后只有在它们全部完成后我才希望 target.out
运行(即链接器)。
虽然我不想这样调用它:$(MAKE) target.out
因为在我真正的 makefile 中我有很多变量都设置...
我已经尝试查看(从其他答案).NOT_PARALLEL
并使用 dep order operator |
(管道),并且我已经尝试订购大量规则以将 target.out 放在最后....但是 -j
选项只是遍历所有这些并破坏了我的顺序:( ...必须有一些简单的方法来做到这一点吗?
最佳答案
编辑:添加将变量传递给子品牌的方法示例。通过将 $(SUBDIRS)
添加到 build
的先决条件而不是在其配方中进行优化。
我不确定我是否完全理解您的组织,但处理子目录的一种解决方案如下。我假设,有点像您的示例,构建子目录 foo
在顶级目录中生成 foo.o
。我还假设您的顶级 Makefile 定义了您希望在构建子目录时传递给子品牌的变量(VAR1
、VAR2
...)。
VAR1 := some-value
VAR2 := some-other-value
...
SUBDIRS := foo bar baz
SUBOBJS := $(patsubst %,%.o,$(SUBDIRS))
.PHONY: build clean $(SUBDIRS)
build: $(SUBDIRS)
$(MAKE) top
$(SUBDIRS):
$(MAKE) -C $@ VAR1=$(VAR1) VAR2=$(VAR2) ...
top: top.o $(SUBOBJS)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
top.o: top.cc
$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
rm -f top top.o $(SUBOBJS)
for d in $(SUBDIRS); do $(MAKE) -C $$d clean; done
这是并行安全的,并保证只有在所有子构建完成后才会发生链接。请注意,您还可以export
要传递给子 make 的变量,而不是在命令行中传递它们:
VAR1 := some-value
VAR2 := some-other-value
...
export VAR1 VAR2 ...
关于c++ - 并行调用所有子目录上的 gnumake (-j),然后才最后运行链接器规则(即重要顺序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53575593/
我需要在 nginx-ingress 版本上允许来自多个来源的请求:http://localhost:4200、http://localhost:4242 等1.7.1.但我无法对多个来源执行此操作,
我正在部署我使用 APIGILITY 开发的 API到 IIS。由于 IIS 不支持 .htaccess,我试图从 .htaccess 文件的内容创建 web.config 文件。我使用 IISv7.
我正在尝试更改上面 css 样式中的“宽度”规则。在“inspect element”中你可以看到宽度是1008px。我不希望它是 1008px 但它不会让我在 css 样式中更改它你可以看到它被“删
外部css赋值有2种方法,我用的是第一种;大多数网站使用第二种方法。我想知道我是否做错了! 第一种方法: 为几乎每个 css 规则创建一个类并在任何地方使用它们。 blah blah .f_
RDF使用 WEB 标识符 (URIs) 来标识资源,使用属性和属性值来描述资源 RDF 资源、属性和属性值 RDF使用 WEB 标识符来标识事物,并通过属性和属性值来描述资源。 关于资源、属性
我想挖掘特定的 rhs 规则。文档中有一个示例证明这是可能的,但仅适用于特定情况(如下所示)。先来一个数据集来说明我的问题: input {b=100002} 0.2500000 0.250000
我想让 nginx 从网站根目录(:http://localhost:8080/)提供一个静态文件,但它为我的代理通行证提供服务;它提供“/”规则而不是“=/”。 这是我的 nginx 配置的样子:
根据gnu make documentation , 如果一个规则通过一次调用生成多个目标(例如,一个配方执行一个带有多个输出文件的工具),你可以使用 '&:' 规则语法来告诉 make。但是,当在多
我已阅读Firebase Documentation并且不明白什么是 .contains()。 以下是文档中 Firebase 数据库的示例规则: { "rules": { "rooms"
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
我正在尝试做一些多态性练习,但我无法弄清楚这种多态性是如何工作的。我没有找到任何关于这种练习的深入信息。希望大家能给我一些解释。 练习1: class Top { public void m(
为了调试复杂的 XSLT 转换,我将其分为几个部分:首先构建 %.1.xml,然后使用它构建 %.2.xml ,最后构建 %.3.xml。一切正常,但如果我要求 Make 构建最后一个,Make 总是
我尝试了 hacerrank 的 slove 练习 Click我不知道如何添加这些规则: ► 它可以包含 4 个一组的数字,并用一个连字符“-”分隔。 ► 不得有 4 个或更多连续重复数字。 这是我的
我正在尝试编写一个小测验,我希望“再试一次”按钮遵循与“else”之前的“if”语句相同的规则 using System; public class Program { public stat
在我的 Spring/Boot Java 项目中,我有一组服务方法,例如以下一个: @Override public Decision create(String name, String descr
我正在阅读 Covariant virtual function .上面写着 假设 B::f 覆盖了虚函数 A::f。如果满足以下所有条件,A::f 和 B::f 的返回类型可能不同: 1) The
我工作的公司想要分发(在公共(public)链接中)具有内部签名的应用程序。我很确定 Apple 否认这种事情,但我在官方文档/契约(Contract)中没有找到任何相关信息。 有谁知道它到底是如何工
我是 CSS 新手。我观察到一个奇怪的 CSS 行为,其中一个元素具有以下 CSS 属性 .container .header{ color: #FFFFFF; font-size: 2em;
这个问题在这里已经有了答案: Is there a CSS selector for elements containing certain text? (21 个答案) 关闭 7 年前。
我有以下 CSS: workoutcal.css: .errorlist{ color:red; } 以下基本模板: base.html: {% load static %} {
我是一名优秀的程序员,十分优秀!