GNU make manual 翻译(二十)

简介:
继续翻译

复制代码
2.4 Variables Make Makefiles Simpler                        
====================================                        
                        
In our example, we had to list all the object files twice in the rule                        
for `edit' (repeated here):                        
                        
     edit : main.o kbd.o command.o display.o \                        
                   insert.o search.o files.o utils.o                        
             cc -o edit main.o kbd.o command.o display.o \                        
                   insert.o search.o files.o utils.o                        
                        
   Such duplication is error-prone; if a new object file is added to the 
system, we might add it to one list and forget the other.  We can
eliminate the risk and simplify the makefile by using a variable. 
Variables allow a text string to be defined once and substituted in 
multiple places later (*note How to Use Variables: Using Variables.).  
复制代码
2.4 变量使得makefile 更加简单 
====================================
在我们的例子中,我们在 edit 的规则里面,不得不列举了所有目标文件两次:

edit : main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o
cc -o edit main.o kbd.o command.o display.o \
insert.o search.o files.o utils.o

这种重复容易导致出错;如果一个新的 目标文件被加入到系统中,我们也许会在某处加入了,而某处忘记了加入。

我们可以通过使用变量,来消除这个风险,简化makefile。

变量允许一个文本串定义一次,到处使用(*not How to Use Variables:Using Variables)。

后文待续

本文转自健哥的数据花园博客园博客,原文链接http://www.cnblogs.com/gaojian/archive/2012/09/13/2683394.html,如需转载请自行联系原作者

目录
相关文章
|
Linux C语言
make: gcc:命令未找到
make: gcc:命令未找到
make: gcc:命令未找到
|
C语言 C++ Perl
如何处理错误消息Please install the gcc make perl packages
如何处理错误消息Please install the gcc make perl packages
142 0