2016-03-03 118 views
1

我试图构建gcc-5.3和binutils-2.26。我这样做了:GCC&binutils构建 - C编译器无法创建可执行文件

mkdir gcc; cd gcc 
wget http://path/to/gcc-5.3.0.tar.bz2 
wget http://path/to/binutils-2.26.tar.bz2 
tar xf gcc-5.3.0.tar.bz2 
tar xf binutils-2.26.tar.bz2 
cd gcc-5.3.0 
contrib/download_prerequisites 
for file in ../binutils-2.26/*; do ln -s "${file}"; done 
cd .. 
mkdir build 
mkdir dist 
cd build 
../gcc-5.3.0/configure --prefix=/home/teamcity/gcc/dist --disable-multilib --with-system-zlib --enable-languages=c,c++,fortran --program-suffix=-mine 
make 

这似乎是构建第一阶段的可执行文件好吗; prev-gas,prev-gcc,prev-ld都与他们看起来似乎合理的可执行文件。但下一阶段失败:

Configuring stage 2 in ./intl 
configure: loading cache ./config.cache 
checking whether make sets $(MAKE)... yes 
checking for a BSD-compatible install... /usr/bin/install -c 
checking whether NLS is requested... yes 
checking for msgfmt... /usr/bin/msgfmt 
checking for gmsgfmt... /usr/bin/msgfmt 
checking for xgettext... /usr/bin/xgettext 
checking for msgmerge... /usr/bin/msgmerge 
checking for x86_64-unknown-linux-gnu-gcc... /home/teamcity/gcc/build/./prev-gcc/xgcc -B/home/teamcity/gcc/build/./prev-gcc/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/lib/ -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/include -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/sys-include -L/home/teamcity/gcc/build/./ld 
checking for C compiler default output file name... 
configure: error: in `/home/teamcity/gcc/build/intl': 
configure: error: C compiler cannot create executables 
See `config.log' for more details. 

的config.log的相关位似乎是这样的:

configure:2978: checking for C compiler default output file name 
configure:3000: /home/teamcity/gcc/build/./prev-gcc/xgcc -B/home/teamcity/gcc/build/./prev-gcc/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unkn 
own-linux-gnu/bin/ -B/home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/lib/ -isystem /home/teamcity/gcc/dist/x86_64-unknown-linux-gnu/include -isystem /home/teamcity/gcc/dist/x86_64-unknown-l 
inux-gnu/sys-include -L/home/teamcity/gcc/build/./ld -g -O2 -gtoggle -static-libstdc++ -static-libgcc conftest.c >&5 
/home/teamcity/gcc/build/./prev-gcc/as: 106: exec: /home/teamcity/gcc/build/./gas/as-new: not found 

这看起来像上一个-gcc的如希望找到gas/as-new,而实际上它是prev-gas/as-new

有没有一些解决方法呢?是否安全到ln -s prev-gas gas?我有点期待以后会引起问题。难道不可能一起构建这两个版本的gcc和binutils吗?

+0

错字: wget http://path/to/binutils-5.3.0.tar.bz2应该在路径中可能有2.26而不是5.3.0? –

+0

完全正确。我会解决它。 – Tom

+0

还应该提到构建平台是Ubuntu 14.04,使用与系统安装的GCC 4.8。 – Tom

回答

0

这是我自己在Ubuntu 14.04 Azure虚拟机上尝试它后编辑的答案。

以下办法为我工作:

  • 构建和安装的binutils 2.26;为了讨论的目的,我们假设它被安装在/opt/gcc-5.3.0中。
  • 假设gcc-5.3.0和生成目录objdir处于相同的 级别,在构建目录中使用/root/objdir/../gcc-5.3.0/configure --prefix=/opt/gcc-5.3.0 --enable-languages=c,c++ --disable-multilib --with-ld=/opt/gcc-5.3.0/bin/ld --with-as=/opt/gcc-5.3.0/bin/as配置gcc-5.3.0。
  • makemake installobjdir建立目录。

为了验证由新建成gcc使用的ld是一个来自新的binutils:

/opt/gcc-5.3.0/bin/gcc -print-prog-name=ld 

输出应,在本实施例中:

/opt/gcc-5.3.0/bin/ld 

另一个测试:重命名系统ld,在我的情况下为/usr/bin/ld;新建的gcc仍然可以工作。

当然,这适用于ldas

将AS和LD环境变量设置为指向binutils包中新建的二进制文件不起作用:-print-prog-name=...仍显示默认工具,并且删除/重命名默认工具会导致gcc失败。

因此,完成此操作的最佳方法是首先构建binutils,然后使用--with-ld--with-as选项至configure。如果您还想确保使用新建的binutils来构建GCC,则可能需要在系统提供的工具之前将它们放入PATH中,或者甚至可以重命名系统提供的工具以使其不在图片。

感谢您使用另一个邮件列表来验证构建GCC和binutils一起工作,除非它们从源代码管理控件中被取消,我猜这个选项在使用下载的tarball时不适用。总的来说这是一个有趣的练习。

+0

我试过这个。但是,然后建立的GCC最终使用系统ld,而不是binutils 2.26中的那个。 – Tom

+0

我现在看到。我发现了一些与您所描述的相似的说明,但这些说明都是6-7岁,可能已经发生了变化。当我找到时间时,我会在Ubuntu 14.04上玩它,看起来像一个有趣的问题。 – OmniProg

+0

我已经通过构建binutils,安装,然后使用'AS =/path/to/as-mine'和'LD =/path/to/ld-mine'配置gcc来完成它的工作。我读过,你也可以使用'--with-as = ...'和'--with-ld = ...'作为配置选项,但还没有尝试过。 – Tom

相关问题