Make: managing separate compilation(“make”程序:对所有编译单元进行管理)

Make: managing separate compilation(对源代码的处理:单个编译)
When using separate compilation (breaking code into a number of
当进行单个编译时(即将源代码拆分与若干个编译单元),
translation units), you need some way to automatically compile
得需要一些方法以对那些编译单元自动地进行处理,并告诉linker将这些
each file and to tell the linker to build all the pieces —— along with the
单元组合成一可执行的文件(同时还包含一些相关的库函数和启动代码)。
appropriate libraries and startup code —— into an executable file.
Most compilers allow you to do this with a single command-line
用绝大多数编译器,仅仅依靠一个简单的命令行指令就可以完成这一切。
statement. For the GNU C++ compiler, for example, you might say
例如在GNU C++编译器下,可以用“g++ SourceFile1.cpp SourceFile2.cpp”指令。
 g++ SourceFile1.cpp SourceFile2.cpp

The problem with this approach is that the compiler will first
用上面所述的方法时,一个问题就是不管那些文件需要再编译与否
compile each individual file, regardless of whether that file
编译器一上来就对单个文件进行编译。
needs to be rebuilt or not. With many files in a project, it can become
对一个工程中的大多数文件来说,如果只是改了一两个文件的话,再对所有文件进行
prohibitive to recompile everything if you've changed only a single
再编译肯定是有些浪费的。
file.


The solution to this problem, developed on Unix but available
对此问题的解决方法,此方法起源于Unix而现在可以在其它的别的地主也可用了,
everywhere in some form, is a program called make . The make  
是一个叫作“make”的程序。
utility manages all the individual files in a project by following the
“make”程序通过照着在一名为“makefile”文件中的指令组管理那些单个源文件。
instructions in a text file called a makefile. When you edit some of
当对一个工程中的编辑后,再输入“make”时,这个“make”程序就按“makefile”
the files in a project and type make  , the  make  program follows the
的指示,开始对源文件的编辑日期与相应目标文件的日期进行逐个比较,
guidelines in the makefile  to compare the dates on the source code
files to the dates on the corresponding target files, and if a source
若一个源文件的日期比它对应目标文件的日期更早些,“make”程序会通知编译器
code file date is more recent than its target file, make  invokes the
对此文件进行编译。
compiler on the source code file. make  only recompiles the source
这样“make”程序就只对那些已改文件与受此已改文件影响的文件进行编译了。
code files that were changed, and any other source-code files that
are affected by the modified files. By using make, you don't have to
应用“make”程序,当只是对一个工程中的单个文件修改后,你就不必
re-compile all the files in your project every time you make a
再对所有的文件进行再编译了,也就不必再验证所有编译的完成效果了。
change, nor do you have to check to see that everything was built
properly. The makefile  contains all the commands to put your
在“makefile”文件中包含了用来将所有工程组合在一起的指令。
project together. Learning to use make  will save you a lot of time
掌握了如何应用"make"程序,你就可以省去大量的时间,也就不必再为那些多
and frustration. You'll also discover that make is the typical way
麻烦而犹豫了。 随后你会发现,往Linux或Unix系统中安装新软件时,“make”程序是
that you install new software on a Linux/Unix machine (although
常用的一种途经(当然,那些“makefile”程序要远比本书中所展显的
those  makefiles tend to be far more complicated than the ones
复杂的多)presented in this book, and you'll often automatically generate a
makefile for your particular machine as part of the installation
process).

Because  make is available in some form for virtually all C++
由于对几乎所有的C++编译器来说,“make”程序都是可用的,
compilers (and even if it isn't, you can use freely-available makes
(即随对有的编译器不可用时,你也会找到一些相应的免费“makes”程序)
with any compiler), it will be the tool used throughout this book.
在整本书中,“make”也将是常用的工具。
However, compiler vendors have also created their own project
不过,一些编译器厂商也会编写他们自用的编译工具。
building tools. These tools ask you which files are in your project
使用时,这些工具会问要求你确定工程中都有那些文件,并自已判断出
and determine all the relationships themselves. These tools use
这些文件间的关系。
something similar to a makefile , generally called a project file, but
这些工具使用一与makefile类似机制(通常叫做“工程文件”),不过 
the programming environment maintains this file so you don't 
整个编程环境会对此文件进行维护,你也就不必再为此分心了。
have to worry about it. The configuration and use of project files
对这个“工程文件”的设置与应用也会因编程环境而有所不同
varies from one development environment to another, so you must
,这样你就得自己去寻找那些合适的文档帮助了。
find the appropriate documentation on how to use them (although
project file tools provided by compiler vendors are usually so
simple to use that you can learn them by playing around — my
favorite form of education). 

The  makefiles used within this book should work even if you are
最后说一下,即便是你用一个特殊厂商的编译器,本书中所用的makefiles
also using a specific vendor's project-building tool.
也仍然的有效。
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值