GNU 一次构建多个文件
我需要使用 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.c
和 hello2.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想在 GNU make 中默认构建多个目标,你会生成一个“假”目标,一个依赖于你的两个结果的虚拟目标,例如:
这将构建
hello
和hello2
如果您运行make
或make Both
。参考
对于automake,你只需要定义这两个程序:
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:
This will build both
hello
andhello2
if you runmake
ormake both
.Reference
For automake, you just need to define both programs:
使用
make -j num
同时编译num个文件。您可以省略num
并让 make 同时编译尽可能多的文件。通常,如果您同时编译的文件数量多于系统中的 CPU/内核数量,则速度不会变得更快。确保在使用它之前列出所有依赖项。Use
make -j num
to compile num files at the same time. You can omitnum
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.即使使用 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 runningmake
. 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)