GNU 一次构建多个文件

发布于 2024-12-18 04:53:23 字数 815 浏览 1 评论 0原文

我需要使用 GNU 构建系统一次编译多个文件。到目前为止,我只看到过如何一次编译一个文件的示例。这是我最喜欢的参考:

http://www.scs.stanford。 edu/~reddy/links/gnu/tutorial.pdf

它说:

'Makefile.am'

bin_PROGRAMS = hello

hello_SOURCES = hello.c

'configure.ac'

AC_INIT([Hello Program],[1.0],

[Author Of The Program <[email protected]>],

[hello])

AC_CONFIG_AUX_DIR(config)

AM_INIT_AUTOMAKE([dist-bzip2])

AC_PROG_CC

AC_PROG_INSTALL

AC_CONFIG_FILES([Makefile])

AC_OUTPUT

但是如果我该怎么办想要做hello.chello2.c 同时存在?

I need to use GNU build system to compile many files at once. So far, I've only seen examples on how to compile one file at once. This is my favorite reference:

http://www.scs.stanford.edu/~reddy/links/gnu/tutorial.pdf

It says:

‘Makefile.am’

bin_PROGRAMS = hello

hello_SOURCES = hello.c

‘configure.ac’

AC_INIT([Hello Program],[1.0],

[Author Of The Program <[email protected]>],

[hello])

AC_CONFIG_AUX_DIR(config)

AM_INIT_AUTOMAKE([dist-bzip2])

AC_PROG_CC

AC_PROG_INSTALL

AC_CONFIG_FILES([Makefile])

AC_OUTPUT

But what do I do if I want to make hello.c and hello2.c at the same time?

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

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

发布评论

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

评论(3

俯瞰星空 2024-12-25 04:53:23

如果你想在 GNU make 中默认构建多个目标,你会生成一个“假”目标,一个依赖于你的两个结果的虚拟目标,例如:

.PHONY: both
both: hello hello2
hello: hello.o
hello2: hello2.o
hello2.o: hello2.c

这将构建 hellohello2 如果您运行 makemake Both

参考

对于automake,你只需要定义这两个程序:

bin_PROGRAMS = hello hello2

hello_SOURCES = hello.c
hello2_SOURCES = hello2.c

If you want to build multiple targets by default in GNU make, you generate a "phony" target, a virtual target that depends on both of your results, e.g:

.PHONY: both
both: hello hello2
hello: hello.o
hello2: hello2.o
hello2.o: hello2.c

This will build both hello and hello2 if you run make or make both.

Reference

For automake, you just need to define both programs:

bin_PROGRAMS = hello hello2

hello_SOURCES = hello.c
hello2_SOURCES = hello2.c
用心笑 2024-12-25 04:53:23

使用make -j num同时编译num个文件。您可以省略 num 并让 make 同时编译尽可能多的文件。通常,如果您同时编译的文件数量多于系统中的 CPU/内核数量,则速度不会变得更快。确保在使用它之前列出所有依赖项。

Use make -j num to compile num files at the same time. You can omit num and let make compile as much files at the same time as possible. Usually it does not make things faster any more if you compile more files at the same time than you have CPUs/cores in your system. Make sure that all dependencies are listed before using this.

眼中杀气 2024-12-25 04:53:23

即使使用 automake,它也只会为您生成 Makefile。您最终会使用简单的 make 命令。

运行 make 时添加命令行选项 -j。它将指示它并行运行尽可能多的构建命令。您还可以使用 -j 4 自行指定最大并发构建数。 (通常好的值是 nbrProcessors+1)

Even if using automake, it only generates the Makefile for you. You end up using the plain make command.

Add command line option -j when running make. It will instruct it to run as many build commands as it can in parallel. You can also specify the maximum number of concurrent builds yourself with -j 4. (Usual good value is nbrProcessors+1)

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