简体   繁体   English

Makefile项目-通过“ -j”参数使用多个作业时防止构建失败

[英]Makefile project - Preventing build failure when using multiple jobs via “-j” argument

I have a number of simple C++ Makefile projects using GNU Make style makefiles I've manually written, rather than using Automake or CMake. 我有许多使用我手动编写的GNU Make样式makefile而不是使用Automake或CMake的简单C ++ Makefile项目。 The most sophisticated mechanism in them is the use of pkginfo to get compile-time flags and include paths for a handful of third-party libraries. 它们中最复杂的机制是使用pkginfo来获取编译时标志,并包含一些第三方库的路径。

I am able to greatly speed up my builds on my current hardware (Intel i7 quad core) via running make like, so, assuming 4 cores on the machine: 我可以通过运行make like大大加快我当前硬件(Intel i7四核)的构建速度,因此,假设机器上有4个核:

make -j5 -l4

However, some projects, which build fine when run serially (ie: j1), fail when I allow multiple jobs. 但是,当我允许多个作业时,某些在串行运行时可以正常运行的项目(即:j1)失败了。 These projects that fail are essentially a set of projects that are built in sequence from a "master" makefile, and certain dependencies are built out of order. 这些失败的项目实质上是从“主” makefile按顺序构建的一组项目,并且某些依存关系是按顺序构建的。

Assuming I have a list of projects like so: 假设我有一个像这样的项目清单:

library1 (all other projects depend on this)
library2 (all other projects depend on this)
library3 (some other projects depend on this)
example1
...
example20

Is there a simple/de-facto "standard" way of putting a marker/rule in place so that the master makefile builds the libraries first serially, then allows the remaining example projects to build in any which order? 是否有一种简单/实际的“标准”方法来放置标记/规则,以便主makefile可以首先顺序构建库,然后允许其余示例项目以任何顺序构建?

Thank you. 谢谢。

Maybe I didn't understand, but why don't you artificially declare library 2 to depend on library 1 in the master makefile, and library 3 to depend on 1 and 2, etc. Then it should only be possible for them to build serially. 也许我听不懂,但是为什么不人工地声明库2依赖于主makefile中的库1,而库3依赖于1和2,依此类推。那么它们应该只能串行构建。

I don't know if there's a special makefile language or option for this, would be keen to learn. 我不知道是否有特殊的Makefile语言或选项,因此不希望学习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM