GNU make's -j option

前端 未结 6 534
走了就别回头了
走了就别回头了 2021-01-31 07:21

Ever since I learned about -j I\'ve used -j8 blithely. The other day I was compiling an atlas installation and the make failed. Eventually I tracked it down to things being ma

6条回答
  •  囚心锁ツ
    2021-01-31 08:16

    Here's an example of a problem that I ran into when I started using parallel builds. I have a target called "fresh" that I use to rebuild the target from scratch (a "fresh" build). In the past, I coded the "fresh" target by simply indicating "clean" and then "build" as dependencies.

    build: ## builds the default target
    clean: ## removes generated files
    fresh: clean build ## works for -j1 but fails for -j2
    

    That worked fine until I started using parallel builds, but with parallel builds, it attempts to do both "clean" and "build" simultaneously. So I changed the definition of "fresh" as follows in order to guarantee the correct order of operations.

    fresh:
        $(MAKE) clean
        $(MAKE) build
    

    This is fundamentally just a matter of specifying dependencies correctly. The trick is that parallel builds are more strict about this than are single-threaded builds. My example demonstrates that a list of dependencies for given target does not necessarily indicate the order of execution.

提交回复
热议问题