📄 make-11.html
字号:
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
可能在后期的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">版本中,会提供一种在并行执行时防止同时多个“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">ar</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”命令对同一静态库的操作的机制。但是就目前的版本来说,这个问题是存在的。因此要求我们在书写</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Makefile</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">时,加入控制策略来避免</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">并发执行时多个“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">ar</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”命令同时操作同一个静态库文件。或者放弃使用</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">的并发执行功能。</span></p>
<h2><a name="_gnu_make_11.4"><span style="font-size: 14pt" lang="en-us"><b>1</b></span><b><span lang="EN-US" style="font-size: 14.0pt">1.4<span style="font-style: normal; font-variant: normal; font-weight: normal; font-size: 7.0pt; font-family: Times New Roman">
</span></span></b><span style="font-size: 14.0pt; font-family: 楷体_GB2312">
静态库的后缀规则</span></a></h2>
<span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; color: #222222">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
静态库的后缀规则属于后缀规则的特殊应用,后缀规则在目前版本的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">GNU
make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">中已经被模式规则替代。但目前版本</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">同样支持旧风格的后缀规则,主要是为了兼容老版本的</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">。对于静态库的重建也可以使用后缀规则。目标后缀需要是“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”(在</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Linux</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">(</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">Unix</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">)中、静态库的后缀为</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">)。例如这样一个后缀规则:</span></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 29.95pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">.c.a:</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(CC) $(CFLAGS)
$(CPPFLAGS) -c $< -o $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(AR) r $@ $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(RM) $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
它相当于模式规则:</span></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-indent: 13.8pt; margin-left: 29.95pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span><b><i><span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">(%.o):
%.c</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(CC) $(CFLAGS)
$(CPPFLAGS) -c $< -o $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(AR) r $@ $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 13.85pt; margin-left: 58.2pt"><b><i>
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial">$(RM) $*.o</span></i></b></p>
<p class="MsoNormal" style="text-indent: 20.5pt">
<span lang="EN-US" style="font-size: 12.0pt; font-family: Arial"> </span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
对于老风格的后缀规则,它的目标是“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.a.c</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”,当转换为模式规则时。后缀规则中的“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”被作为模式规则的目标文件后缀(目标文件就是</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">N.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">);“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.c</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”被作为了模式规则依赖文件的后缀(依赖文件就是</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">N.c</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">)。</span></p>
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
存在这样一种情况:可能一个不是静态库的文件使用了后缀</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">。那么</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">也会按照正常的方式静态库的后缀规则转换成为一个模式规则。因此对于一个双后缀规则的目标“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">.<i>x</i>.a</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”,经过</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">make</span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">转换后会产生两个模式规则:“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">(%.o):
%.<i>x</i></span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”</span><span style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">
</span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
和“</span><span lang="EN-US" style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">%.a:
%.<i>x</i></span><span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">”。具体的转换过程可参考</span><span style="font-size: 12.0pt; line-height: 150%; font-family: Arial; color: black">
<span lang="EN-US"><span lang="EN-US" style="font-family: 楷体_GB2312">后缀规则</span>
</span></span>
<span style="font-size: 12.0pt; line-height: 150%; font-family: 楷体_GB2312; color: black">
一节</span></p>
<hr size="1" width="100%" align="center"></span>
<span style="font-size: 12.0pt; font-family: Arial; ">
<p class="MsoNormal" style="text-align: justify; text-justify: inter-ideograph; text-indent: 24.0pt; line-height: 150%; text-autospace: ideograph-numeric ideograph-other">
<font face="楷体_GB2312" size="4"><a href="make-12.html">下一章</a>
<a href="make-10.html">上一章</a> <a href="index.html#content">目录</a></font></p>
</span>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -