📄 adjusting.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>
5.7. 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 5. 构建临时编译环境
</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="tcl.html" title="Tcl-8.4.9">前进</a>
<p>
Tcl-8.4.9
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter05.html" title="Chapter 5. 构建临时编译环境">上一级</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">
5.7. 调整工具链
</h1>
</div>
<p>现在临时的C库已经装好,接下来本章中要编译的所有工具应该连接到这些库。为了达到这个目标,需要调整连接器和编译器的specs文件。
</p>
<p>在第一遍编译 Binutils 快结束的时候,已经把连接器调整过了,通过在 <tt class="filename">binutils-build</tt> 目录下执行以下的命令就可安装:
</p>
<pre class="userinput"><kbd class="command">make -C ld install</kbd></pre>
<p>从现在开始,所有东西都连接到 <tt class="filename">/tools/lib</tt> 里面的库文件。
</p>
<div class="note">
<div class="admonhead">
<img alt="[Note]" src="../images/note.png" />
<h3 class="admontitle">
注意
</h3>
</div>
<div class="admonbody">
<p>如果前面你忽略了保留 Binutils 源代码和编译目录的提示,就忽略上面的命令。这将有可能导致测试用的一些程序连接到主机的库文件上。这当然不理想,但不是大问题。这种状况在接下来第二遍安装 Binutils 的时候会被纠正过来。
</p>
</div>
</div>
<p>现在调整过的连接器已经装好了,Binutils 编译目录和源代码目录现在可以删掉了。
</p>
<p>下面要做的是修正 GCC 的 specs 文件,使它指向新的动态连接器。一个简单的 sed 命令就能做到:
</p>
<pre class="userinput"><kbd class="command">SPECFILE=`gcc --print-file specs` &&
sed 's@ /lib/ld-linux.so.2@ /tools/lib/ld-linux.so.2@g' \
$SPECFILE > tempspecfile &&
mv -f tempspecfile $SPECFILE &&
unset SPECFILE</kbd></pre>
<p>
<span>推荐你拷贝和粘贴上面的命令,而不是手动输入。</span>当然你也可以手动编辑 specs 文件,只要把所有的
“<span class="quote">/lib/ld-linux.so.2</span>” 都替换成 “<span class="quote">/tools/lib/ld-linux.so.2</span>” 就行了。
</p>
<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="toolchaintechnotes.html" title="5.2. Toolchain Technical Notes">Section 5.2, “工具链技术说明”</a>。</p>
</div>
</div>
<p>最后,有些主系统里的头文件可能会跑到 gcc 的头文件目录里,这可能是因为 GCC 的“<span class="quote">fixincludes</span>”脚本在编译 GCC 的过程中运行了。我们将在本章后面详细的解释这个脚本。现在,执行下面的命令,以避免头文件混淆:
</p>
<pre class="userinput"><kbd class="command">rm -f /tools/lib/gcc/*/*/include/{pthread.h,bits/sigthread.h}</kbd></pre>
<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 ': /tools'</kbd></pre>
<p>如果一切正常,应该不会出错,而且最后一个命令的结果应当是:
</p>
<pre class="screen"><tt class="computeroutput">[Requesting program interpreter: /tools/lib/ld-linux.so.2]</tt></pre>
<p>注意,<tt class="filename">/tools/lib</tt> 应该是动态连接器的前缀。
</p>
<p>如果输出不是像上面那样或者根本没有输出,那么就有大问题了。返回并检查前面的操作,找出问题,并改正过来。在改正之前,不要继续后面的部份,因为这样做没有意义。首先,再次上述合理性检查,用 <span><strong class="command">gcc</strong></span> 代替 <span><strong class="command">cc</strong></span>,如果工作正常,那么是因为 <tt class="filename">/tools/bin/cc</tt> 这个符号链接丢失了。回头看看 <a href="gcc-pass1.html" title="5.4. GCC-3.4.3 - Pass 1">Section 5.4 “GCC-3.4.3 - 第一遍”</a> 并建立符号链接。接下来,确保 <tt class="envar">PATH</tt> 正确。检查时,运行 <span><strong class="command">echo $PATH</strong></span> 并检查 <tt class="filename">/tools/bin</tt> 是否在列表的最前面。如果 <tt class="envar">PATH</tt> 错误,可能时因为你没有以 <span class="emphasis"><em>lfs</em></span> 用户登录,或者在<a href="../chapter04/settingenvironment.html" title="4.4. Setting Up the Environment">Section 4.4 “设置工作环境”</a>的部分出错了。另外一个原因可能是上面修正 specs 文件时出错,如果这样,重新修改 specs 文件,复制粘贴时小心。
</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="tcl.html" title="Tcl-8.4.9">前进</a>
<p>
Tcl-8.4.9
</p>
</li>
<li class="up">
<a accesskey="u" href="chapter05.html" title="Chapter 5. 构建临时编译环境">上一级</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 + -