📄 readjusting.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=gb2312" />
<title>
6.12. Re-adjusting the Toolchain
</title>
<link rel="stylesheet" href="../stylesheets/lfs.css" type="text/css" />
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1" />
<link rel="stylesheet" href="../stylesheets/lfs-print.css" type="text/css" media="print" />
</head>
<body id="lfs" class="6.1">
<div class="navheader">
<div class="headertitles">
<h4>
Linux From Scratch - Version 6.1
</h4>
<h3>
Chapter 6. 安装系统基础软件
</h3>
</div>
<ul class="headerlinks">
<li class="prev">
<a accesskey="p" href="glibc.html" title="Glibc-2.3.4">后退</a>
<p>
Glibc-2.3.4
</p>
</li>
<li class="next">
<a accesskey="n" href="binutils.html" title="Binutils-2.15.94.0.2.2">前进</a>
<p>
Binutils-2.15.94.0.2.2
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title="Chapter 6. 安装系统基础软件">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
</li>
</ul>
</div>
<div class="sect1" lang="zh_cn" xml:lang="zh_cn">
<div class="titlepage">
<h1 class="sect1">
6.12. 再次调整工具链
</h1>
</div>
<p>现在,最终的 C 库已经安装好了,我们需要再次调整工具链,让本章随后编译的那些工具都连接到这个库上。基本上,就是把<a href="../chapter05/chapter05.html">Chapter 5</a>中“<span class="quote">调整工具链</span>”那里做的调整给取消掉。<a href="../chapter05/chapter05.html">Chapter 5</a>中,工具链使用的库是从宿主系统的 <tt class="filename">/{,usr/}lib</tt> 转向新安装的 <tt class="filename">/tools/lib</tt> 目录。同样的,现在工具链使用的库将从临时的 <tt class="filename">/tools/lib</tt> 转向 LFS 系统最终的 <tt class="filename">/{,usr/}lib</tt> 目录。
</p>
<p>首先是调整连接器(我们在上一章第二遍编译 Binutils 的时候,保留了源码和编译目录,就是为了这个目的)。在 <tt class="filename">binutils-build</tt> 目录下用下列命令安装连接器:
</p>
<pre class="userinput"><kbd class="command">make -C ld INSTALL=/tools/bin/install install</kbd></pre>
<div class="note">
<div class="admonhead">
<img alt="[Note]" src="../images/note.png" />
<h3 class="admontitle">
注意
</h3>
</div>
<div class="admonbody">
<p>如果你没看到 <a href="../chapter05/chapter05.html">Chapter 5</a> 中关于保留 Binutils 源码目录和编译目录的警告,或者不小心删除了第二遍 Binutils 的源码目录或编译目录,别紧张,关系不大,别运行上面的命令就行,这样会使下一个软件包 Binutils 连接到 <tt class="filename">/tools</tt> 目录下的Glibc库上,而不是 <tt class="filename">/{,usr/}lib</tt> 下那个。这不太完美,但经过我们的测试,生成的Binutils应该是一模一样的。
</p>
</div>
</div>
<p>从现在起,所有新编译的程序都只连接到 <tt class="filename">/usr/lib</tt> 和 <tt class="filename">/lib</tt> 目录下的库文件上了。指定额外的 <em class="parameter"><tt>INSTALL=/tools/bin/install</tt></em> 参数是因为在第二遍编译 Binutils 时创建的 <tt class="filename">Makefile</tt> 还包含了对目前尚未安装的 <span><strong class="command">/usr/bin/install</strong></span> 的引用。有些宿主系统用 <tt class="filename">ginstall</tt> 符号连接作为 install 的名称,这样将会在这里导致问题,上面的命令也考虑到了这种情况。
</p>
<p>现在,你可以删除 Binutils源码和编译目录了。
</p>
<p>下面要做的是修正 GCC 的 specs 文件,使它指向新的动态连接器。我们用一个 Perl 命令就能做到:
</p>
<pre class="userinput"><kbd class="command">perl -pi -e 's@ /tools/lib/ld-linux.so.2@ /lib/ld-linux.so.2@g;' \
-e 's@\*startfile_prefix_spec:\n@$_/usr/lib/ @g;' \
`gcc --print-file specs`</kbd></pre>
<p>修改之后,用你的眼睛亲自检查一下specs文件,确保已经改正确了。
</p>
<div class="important">
<div class="admonhead">
<img alt="[Important]" src="../images/important.png" />
<h3 class="admontitle">
重要
</h3>
</div>
<div class="admonbody">
<p>如果你的系统平台上,动态连接器的名字不是 <tt class="filename">ld-linux.so.2</tt>,你必须把上面命令里的 “<span class="quote">ld-linux.so.2</span>” 换成你的系统平台上动态连接器的名字。若有必要,请参见 <a href="../chapter05/toolchaintechnotes.html" title="5.2. Toolchain Technical Notes">Section 5.2 “工具链技术说明 ”</a> 。
</p>
</div>
</div>
<div class="caution">
<div class="admonhead">
<img alt="[Caution]" src="../images/caution.png" />
<h3 class="admontitle">
注意
</h3>
</div>
<div class="admonbody">
<p>现在有必要停下来,检查一下新工具链的基本功能(编译和连接)是否正常,我们进行一个简单的合理性检查:
</p>
<pre class="userinput"><kbd class="command">echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /lib'</kbd></pre>
<p>如果一切正常,应该不会出错,而且最后一个命令的结果应该是:
</p>
<pre class="screen"><tt class="computeroutput">[Requesting program interpreter: /lib/ld-linux.so.2]</tt></pre>
<p>注意,<tt class="filename">/lib</tt> 应该是动态连接器的前缀。
</p>
<p>如果你没看到上面的结果,那么就有大问题了。你需要检查一下前面的操作,看看问题出在哪里,并改正过来。在改正之前,不要继续后面的部份,因为没什么意义。大多数情况下,出错都是因为上面的 specs 文件没改对。当然,如果你的平台上动态连接器的名字不是 <tt class="filename">ld-linux.so.2</tt>,上面的结果也会不同。
</p>
<p>在确定一切正常后,删除测试文件:
</p>
<pre class="userinput"><kbd class="command">rm dummy.c a.out</kbd></pre>
</div>
</div>
</div>
<div class="navfooter">
<ul>
<li class="prev">
<a accesskey="p" href="glibc.html" title="Glibc-2.3.4">后退</a>
<p>
Glibc-2.3.4
</p>
</li>
<li class="next">
<a accesskey="n" href="binutils.html" title="Binutils-2.15.94.0.2.2">前进</a>
<p>
Binutils-2.15.94.0.2.2
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter06.html" title="Chapter 6. 安装系统基础软件">上一级</a>.
</li>
<li class="home">
<a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>.
</li>
</ul>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -