⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glibc.html

📁 Linux From Scratch的中文指导,学习LINUX很有用
💻 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.6.&nbsp;Glibc-2.3.4
    </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&nbsp;5.&nbsp;构建临时编译环境
        </h3>
      </div>
      <ul class="headerlinks">
        <li class="prev">
          <a accesskey="p" href="linux-libc-headers.html" title="Linux-Libc-Headers-2.6.11.2">后退</a>
          <p>
            Linux-Libc-Headers-2.6.11.2
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="adjusting.html" title="Adjusting the Toolchain">前进</a>
          <p>
            Adjusting the Toolchain
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter05.html" title="Chapter&nbsp;5.&nbsp;构建临时编译环境">上一级</a>.
        </li>
        <li class="home">
          <a accesskey="h" href="../index.html" title="Linux From Scratch - Version 6.1">回首页</a>
        </li>
      </ul>
    </div>
    <div class="wrap" lang="zh_cn" xml:lang="zh_cn">
      <div class="titlepage">
        <h1 class="sect1">
          5.6. Glibc-2.3.4
        </h1>
      </div>
      <div class="package" lang="zh_cn" xml:lang="zh_cn">
        <p>Glibc 包含了主要的C库。这个库提供了基本例程,用于分配内存、搜索目录、打开关闭文件、读写文件、字串处理、模式匹配、数学计算等等。
        </p>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong><span class="segtitle">预计编译时间:</span></strong> <span class="seg">11.8 SBU</span>
            </div>
            <div class="seg">
              <strong><span class="segtitle">所需磁盘空间:</span></strong> <span class="seg">454 MB</span>
            </div>
          </div>
        </div>
        <div class="segmentedlist">
          <div class="seglistitem">
            <div class="seg">
              <strong><span class="segtitle">安装依赖于:</span></strong> <span class="seg">Bash, Binutils, Coreutils, Diffutils, Gawk, GCC, Gettext, Grep, Make, Perl, Sed, Texinfo</span>
            </div>
          </div>
        </div>
      </div>
      <div class="installation" lang="zh_cn" xml:lang="zh_cn">
        <div class="titlepage">
          <h2 class="sect2">
            5.6.1. Glibc 的安装
          </h2>
        </div>
        <p>如果你把这个包缺省的优化参数(包括 <em class="parameter"><tt>-march</tt></em> 和 <em class="parameter"><tt>-mcpu</tt></em> 参数)改变的话,它会有些不正常的表现。因此,如果你定义了任何优化参数的话,比如 <tt class="envar">CFLAGS</tt> 和 <tt class="envar">CXXFLAGS</tt>,我们劝你在编译 Glibc 时 unset 或修改它们。</p>
        <p>一个值得注意的地方是,使用非本书建议的方法来编译 Glibc ,就是在拿系统的稳定性做赌注。
        </p>
        <p>在2.6.11.x内核下,Glibc会有两个测试项目不能通过,这是既不是Glibc也不是内核的原因,而是测试工具自身的原因造成的。如果你使用的是2.6.11.x的内核,并且想运行测试套件的话,请先打上补丁:
        </p>
        <pre class="userinput"><kbd class="command">patch -Np1 -i ../glibc-2.3.4-fix_test-1.patch</kbd></pre>
        <p>Glibc 文档推荐在源码目录之外的一个专门的编译目录下进行编译:
        </p>
        <pre class="userinput"><kbd class="command">mkdir ../glibc-build
cd ../glibc-build</kbd></pre>
        <p>
          接下来为 Glibc 做编译前的准备:
        </p>
        <pre class="userinput"><kbd class="command">../glibc-2.3.4/configure --prefix=/tools \
    --disable-profile --enable-add-ons \
    --enable-kernel=2.6.0 --with-binutils=/tools/bin \
    --without-gd --with-headers=/tools/include \
    --without-selinux</kbd></pre>
        <p>
          配置选项的意思是:
        </p>
        <div class="variablelist">
          <dl>
            <dt>
              <span class="term"><em class="parameter"><tt>--disable-profile</tt></em></span>
            </dt>
            <dd>
              <p>它关掉了 profiling 信息相关的库文件编译。如果你打算做 profiling ,就省掉这个参数。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--enable-add-ons</tt></em></span>
            </dt>
            <dd>
              <p>这个指示 Glibc 使用附加的 NPTL 包作为线程库。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--enable-kernel=2.6.0</tt></em></span>
            </dt>
            <dd>
              <p>这个告诉 Glibc 编译支持2.6.x内核的库。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--with-binutils=/tools/bin</tt></em></span>
            </dt>
            <dd>
              <p>这个参数并不是必需的。但它们能保证在编译 Glibc 时不会用错 Binutils 程序。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--without-gd</tt></em></span>
            </dt>
            <dd>
              <p>这个参数保证不编译 <span><strong class="command">memusagestat</strong></span> 程序,这个程序会顽固地连接到主系统的库文件(libgd, libpng, libz 等等)。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--with-headers=/tools/include</tt></em></span>
            </dt>
            <dd>
              <p>这个参数指示 Glibc 按照前面刚刚安装到 tools 目录中的内核头文件编译自己,从而精确的知道内核的特性以根据这些特性对自己进行最佳化编译。
              </p>
            </dd>
            <dt>
              <span class="term"><em class="parameter"><tt>--without-selinux</tt></em></span>
            </dt>
            <dd>
              <p>当从一个含有 SELinux 特性的宿主系统(如FC3)编译时,Glibc 将会将 SELinux 支持编译进来。由于 LFS 工具链并不包含 SELinux 支持,所以一个含有 SELinux 特性的 Glibc 将会导致许多操作失败。所以这里明确禁用它。
              </p>
            </dd>
          </dl>
        </div>
        <p>
         在这个阶段你可能会看到下面的警告:
        </p>
        <div class="blockquote">
          <blockquote class="blockquote">
            <pre class="screen"><tt class="computeroutput">configure: WARNING:
*** These auxiliary programs are missing or 
*** incompatible versions: msgfmt
*** some features will be disabled.
*** Check the INSTALL file for required versions.</tt></pre>
          </blockquote>
        </div>
        <p>
          抱怨说缺少或不兼容的 <span><strong class="command">msgfmt</strong></span> 程序,这没有什么大问题,不过有时候可能会在运行测试套件的时候出问题。<span><strong class="command">msgfmt</strong></span> 程序是宿主系统 Gettext 应当提供的一部分。如果担心宿主系统的 <span><strong class="command">msgfmt</strong></span> 有兼容性问题,你可以升级宿主系统的 Gettext ,也可以忽略这个问题而不去管它。
        </p>
        <p>
          编译软件包:
        </p>
        <pre class="userinput"><kbd class="command">make</kbd></pre>
        <p>现在编译完成了。正如前面说过的,在这里运行测试没什么好处,但是如果你坚持要测试的话可以运行下列命令:
        </p>
        <pre class="userinput"><kbd class="command">make check</kbd></pre>
        <p>关于测试失败重要性的讨论请参考这里:<a href="../chapter06/glibc.html" title="6.11.&nbsp;Glibc-2.3.4">Section 6.11, &ldquo;Glibc-2.3.4.&rdquo;</a>
        </p>
        <p>在这一章里,Glibc 的测试套件高度依赖于宿主系统的工具和环境,尤其是内核。因为这个原因,有时错误很难避免,但是无需太在意。<a href="../chapter06/chapter06.html">Chapter 6</a>里面的 Glibc 才是我们最后所使用的,那里的 Glibc 需要通过绝大多数测试。但要注意的是,即使在 <a href="../chapter06/chapter06.html">Chapter 6</a> 里,有的失败还是会出现,比如math测试。
        </p>
        <p>当遇到一个错误时,记录下来,再用 <span><strong class="command">make check</strong></span> 继续。测试套件会从出错的地方继续进行。你也可以用 <span><strong class="command">make -k check</strong></span> 来一次把测试做完。但如果你这样做的话,就要把屏幕输出记录到文件里( <span><strong class="command">make -k check > ck_log</strong></span> ),以便最后检查到底出了多少错,哪些测试出错了。
        </p>
        <p>在安装 Glibc 的过程中,它会警告缺少 <tt class="filename">/tools/etc/ld.so.conf</tt> 文件。其实这没什么关系,不过下面的命令能修正它:
        </p>
        <pre class="userinput"><kbd class="command">mkdir /tools/etc
touch /tools/etc/ld.so.conf</kbd></pre>
        <p>
          安装软件包:
        </p>
        <pre class="userinput"><kbd class="command">make install</kbd></pre>
        <p>不同的国家和文化,使用不同的习俗来交流。这样的习俗很多,从比较简单的时间和日期格式,到非常复杂的语言发音。GNU程序的“internationalization”(国际化,又称i18n,18表示中间的18个字母)是以locales来实现的。
        </p>
        <div class="note">
          <div class="admonhead">
            <img alt="[Note]" src="../images/note.png" />
            <h3 class="admontitle">
              注意
            </h3>
          </div>
          <div class="admonbody">
            <p>如果刚才没有运行测试套件,那么现在就没有必要安装 locales 。在下一章里面我们将会安装。
            </p>
          </div>
        </div>
        <p>如果你一定要安装 locale,请执行下面的命令:
        </p>
        <pre class="userinput"><kbd class="command">make localedata/install-locales</kbd></pre>
        <p>为了节省时间,上一个命令(生成并安装所有的 locale )的替代方案是只安装想要和需要的 locale 。使用 <span><strong class="command">localedef</strong></span> 命令可以做到这一点。这个命令的信息在 Glibc 的代码树里的 <tt class="filename">INSTALL</tt> 文件中有详细叙述。然而,为了将来的软件包测试的通过,许多 locale 还是需要的,比如 GCC 中的 <span class="emphasis"><em>libstdc++</em></span> ,下面的命令能安装运行测试套件所必需的最少 locale :
        </p>
        <pre class="userinput"><kbd class="command">mkdir -p /tools/lib/locale
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i ja_JP -f EUC-JP ja_JP</kbd></pre>
      </div>
      <div class="content" lang="zh_cn" xml:lang="zh_cn">
        <p>关于这个软件包的详细资料位于 <a href="../chapter06/glibc.html#contents-glibc" title="6.11.4.&nbsp;Contents of Glibc">Section&nbsp;6.11.4, &ldquo;Contents of Glibc.&rdquo;</a>
        </p>
      </div>
    </div>
    <div class="navfooter">
      <ul>
        <li class="prev">
          <a accesskey="p" href="linux-libc-headers.html" title="Linux-Libc-Headers-2.6.11.2">后退</a>
          <p>
            Linux-Libc-Headers-2.6.11.2
          </p>
        </li>
        <li class="next">
          <a accesskey="n" href="adjusting.html" title="Adjusting the Toolchain">前进</a>
          <p>
            Adjusting the Toolchain
          </p>
        </li>
        <li class="up">
          <a accesskey="u" href="chapter05.html" title="Chapter&nbsp;5.&nbsp;构建临时编译环境">上一级</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 + -