如何使用make并行构建特定的多个目标? [英] How to build specific multiple targets parallelly using make?

查看:127
本文介绍了如何使用make并行构建特定的多个目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有三个源文件.每个源文件都是对应的目标.例如,a.cp​​p的目标是a,b.cpp是b,c.cpp是c.

There are three source files. Each source files are corresponding targets. For example, the target of a.cpp is a, b.cpp is b, and c.cpp is c.

src/a.cpp
    b.cpp
    c.cpp
build/

我可以使用 -j 选项并行构建目标.

I can build the targets parallelly using -j option.

例如,

cd build
make -j3

目标a,b和c并行构建.

target a, b, and c build parallelly.

有什么方法可以指定一些目标并进行并行构建吗?

Is there any way to specify some of targets and parallel build ?

例如

make -j2 a b

不幸的是,它可以按顺序工作.首先,构建 a ,然后构建 b .我只想并行构建 a b .

Unfortunately, it works sequentially. First, build a and then build b. I want to build only a and b parallelly.

我尝试了以下方法.

make a&
make b&
wait

但是, wait 的返回码是最后一个完成的等待目标.这意味着,如果 make a& 因失败而结束,然后 make b& 成功完成,则 wait 的返回码为0.如果有任何make失败,我想停止构建过程.

However, the return code of the wait is the last finished waiting target. That means if make a& finished with failure and then make b& successfully finished, the return code of wait is 0. I want to stop building process if any of make are failure.

有什么好办法吗?

推荐答案

不幸的是,它可以按顺序工作

Unfortunately, it works sequentially

这是不正确的,正如您通过编写一个小测试可以看到的那样:

That is not true, as you could see from writing a small test:

$ cat Makefile
all: one two

one two:
        @echo start $@
        @sleep 2
        @echo stop $@

$ make
start one
stop one
start two
stop two

$ make -j2
start one
start two
stop one
stop two

$ make -j2 one two
start one
start two
stop one
stop two

如您所见,即使在命令行上提供特定目标时,它们也是并行运行的.如果您没有看到这种现象,则说明您的makefile中有一些与您在问题中所描述的内容大不相同的东西.

As you can see even when providing specific targets on the command line, they are run in parallel. If you are not seeing this behavior then there's something about your makefiles that is materially different than what you've described in your question.

这篇关于如何使用make并行构建特定的多个目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆