gcc - 一起编译 binutils 和 gcc 的方法?

标签 gcc bootstrapping binutils

根据gcc build instructions您可以在构建 gcc(以及 gmp、mpc 等)的同时构建 binutils。

该页面内容如下:

If you also intend to build binutils (either to upgrade an existing installation or for use in place of the corresponding tools of your OS), unpack the binutils distribution either in the same directory or a separate one. In the latter case, add symbolic links to any components of the binutils you intend to build alongside the compiler (bfd, binutils, gas, gprof, ld, opcodes, ...) to the directory containing the GCC sources.

Likewise the GMP, MPFR and MPC libraries can be automatically built together with GCC. Unpack the GMP, MPFR and/or MPC source distributions in the directory containing the GCC sources and rename their directories to gmp, mpfr and mpc, respectively (or use symbolic links with the same name).

这对于 gmp、mpc、mpfr 工作得很好,但我似乎无法让它构建所有 binutils。 我也无法弄清楚如何让它从 binutils 构建新的黄金链接器。 有问题的版本是 gcc-4.4.2 和 binutils-2.20。

分步说明会很棒(对于我以及其他遇到此问题的人来说)。

最佳答案

这应该仍然受到支持,因为它通常用于构建交叉编译器。

事实上,我刚刚使用 gcc 4.6.0 和 binutils 2.21(使用适当版本的 gmp、mpc 和 mpfr)完成了此操作,并且以下内容似乎工作正常:

  • 将要构建的内容的所有文件(gcc-4.6.0.tar.bz2、binutils-2.21.tar.bz2 等)放入新目录中,例如src

  • 将它们全部解压缩到此目录中,因此您最终会得到 gcc-4.6.0/ binutils-2.21/ gmp-5.0 .2/ 以及更多人并排坐着

    tar jxvf gcc-4.6.0.tar.bz2 ...(在此处解压其他文件,观察文件列表滚动过去)

  • cd gcc-4.6.0 并符号链接(symbolic link) gmp、mpc 和 mpfr 目录,链接中不包含版本号,例如:

    ln -s ../gmp-5.0.2 gmp

  • 现在对 gcc 目录中不存在的 binutils 目录中的所有内容进行符号链接(symbolic link),因此已存在的任何内容都将优先,但 binutils 工具对于构建来说将是可见的:

    对于 ../binutils-2.21/* 中的文件;执行 ln -s "${file}";完成

  • 更改目录并创建一个构建目录,以将所有这些内容单独构建到源中(这始终是推荐的方法,并且它往往仍然比在源目录中构建更可靠):

    cd ..; mkdir 构建

  • 此时您应该拥有一组目录和链接,如下所示:

    binutils-2.21/ build / gcc-4.6.0/ gmp -> ../gmp-5.0.2 mpc -> ../mpc-0.9 mpfr -> ../mpfr-3.0.1 bfd -> ../binutils-2.21/bfd binutils -> ../binutils-2.21/binutils 气体 -> ../binutils-2.21/gas ...(这里有更多 binutils 的符号链接(symbolic link),加上现有的 gcc 东西) GMP-5.0.2/ mpc-0.9/ mpfr-3.0.1/

  • 从该目录配置全部内容,使用您需要传递给配置的任何选项:

    ../gcc-4.6.0/configure --prefix=/foo/bar --enable-languages=c,c++,ada

  • 构建、等待、安装(您可能需要使用 make -j4 左右来并行进行一些构建,因为这需要一段时间):

    制作-j4;进行安装

如果尚未将目标添加到您的路径中(如果该目标不在 /etc/ld.so.conf 中指定的范围内,则可能将 lib 目录添加到 LD_LIBRARY_PATH,如消息中所述)关于在 make install 步骤中安装库的信息),并且一切都应该在这个新版本中启动并运行。

打开新 shell 后,可能值得检查一下您是否正在使用此已安装的版本:

    `which gcc`

    `which as`

..以及版本符合您的预期:

    `gcc --version`

    `as --version`

..以及(当然)在您将其释放到代码库之前,通过一些简单的示例测试已安装的版本是否可以正常构建可执行文件:)

编辑:下面的评论包含一些已知可以协同工作的版本集。并非所有组合都有效,因此您可能需要对提到的不同组合进行一些尝试和错误!

稍后编辑:gdb 也可以包含在此版本中(再次需要兼容的组件版本 - 请参阅评论)。 以类似的方式将其添加为 binutils 之后的最后一件事,使用 for f in ../gdb-8.1.1/* ;执行 ln -s "${f}";完成,构建将自动拾取它。

截至 2023 年 5 月 3 日编辑:最新发布版本 gcc 13.1.0、binutils 2.40、gdb 13.1、cloog 0.18.1、isl 0.24、gmp 6.1.0、mpc 1.2.1、mpfr 4.1.0 全部构建在一起很好,至少对于 c、c++、fortran 作为语言集来说是这样。

关于gcc - 一起编译 binutils 和 gcc 的方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1726042/

相关文章:

c - 从目标文件中提取一个部分以分隔 .o

linker - 我需要 "ranlib"/"ar -s"进行静态链接吗?

c - fork 过程中的确定性 malloc

c - C 和汇编之间的链接错误

browser - @angular/platform-b​​rowser 与 @angular/platform-b​​rowser-dynamic

c# - 引导 WPF

linux - 安装 GCC 及其所有依赖项

c - C中的非无意义优化

java - Spring Boot 和解析资源

assembly - 如何在不使用gcc的情况下将使用C标准库的气体汇编程序与ld链接?