解析多线程 make 的输出(-j N)

发布于 2024-10-09 09:48:50 字数 281 浏览 0 评论 0原文

我在公共目录中有很多源目录。当我通过发出命令开始 make 时:

make -j 4

我从 make 的线程接收到大量字符串以及调用的 gcc 编译器实例。 对于解析错误,我必须运行 make 两次,第二次使用一个线程:

make -j 1

这样我就可以正确解析 make 的输出。

有没有一种方法可以运行一次多线程 make 并正确确定与哪个项目(源目录)相关的错误?

谢谢你!

I have a lot of source directories in common directory. When I start make by issuing command:

make -j 4

I receive a lot of strings from make's threads along with invoked gcc compiler instances.
For parsing errors I have to run make twice, second time with one thread:

make -j 1

so I can correctly parse make's output.

Is there a way for running multithreaded make one time and correctly decide which error related to which project (source directory)?

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拒绝两难 2024-10-16 09:48:50

如果您将递归 make(顽皮男孩)与 -j 一起使用,那么您可以使用 shell 脚本包装 Make,该脚本在输出的每一行前面加上唯一的每次 make 调用字符串作为前缀。

$ cat M
#!/bin/bash
PREFIX=$:
exec -a $0 make "$@" 2>&1 | sed "s/^/$PREFIX/"

现在,假设您的 makefile 正确使用 ${MAKE} 来指示递归,我们可以使用 ./M 而不是 make

$ ./M -j --no-print-directory target
28720:/home/user/M -fa.mak
28720:/home/user/M -fb.mak
28720:/home/user/M -fc.mak
28720:/home/user/M -fd.mak
28720:/home/user/M -fe.mak
28720:32484:gcc blah...
28720:31936:/home/user/M -fanother.mak
28720:32484:gcc blah...
28720:31936:gcc blah...
28720:31936:gcc blah...
28720:31936:56781:echo blah...
∶

在这种情况下,每行都以进程 ID 列表为前缀(有利于调试递归 make)。对于您的用例,您可能更喜欢使用 M 来修改源文件名,以便它们成为错误消息中的绝对路径名。

If you are using recursive make (naughty boy) together with -j, then you can wrap Make with a shell script which prefixes each line of output with a unique per-make-invocation string.

$ cat M
#!/bin/bash
PREFIX=$:
exec -a $0 make "$@" 2>&1 | sed "s/^/$PREFIX/"

Now, assuming your makefiles correctly use ${MAKE} to indicate recursion, we can use ./M instead of make.

$ ./M -j --no-print-directory target
28720:/home/user/M -fa.mak
28720:/home/user/M -fb.mak
28720:/home/user/M -fc.mak
28720:/home/user/M -fd.mak
28720:/home/user/M -fe.mak
28720:32484:gcc blah...
28720:31936:/home/user/M -fanother.mak
28720:32484:gcc blah...
28720:31936:gcc blah...
28720:31936:gcc blah...
28720:31936:56781:echo blah...
∶

In this case, each line is prefixed with a list of process IDs (good for debugging recursive make). For your use case, you may prefer M to mangle source file names so that they become absolute pathnames in error messages.

泼猴你往哪里跑 2024-10-16 09:48:50

也许可以切换到pmake?

PMake 设置为以优雅的方式处理多个作业的输出 (

May be it is possible to switch to pmake?

PMake is set up to handle the output from multiple jobs in a graceful fashion (source)

清风夜微凉 2024-10-16 09:48:50

如果您使用某种元构建系统(例如 CMake),请尝试使用 Ninja 来实际运行构建。

它解决了这个问题并且速度更快。

If you're using some kind of meta-build system (eg CMake) try using Ninja to actually run the build.

It solves this problem as well as being quite a lot faster.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文