c++ - GCC 和 binutils build - C 编译器无法创建可执行文件

标签 c++ c gcc build binutils

我正在尝试构建 gcc-5.3 和 binutils-2.26。我是这样做的:

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-gasprev-gccprev-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

这看起来像 prev-gcc 期望找到 gas/as-new,而实际上它是 prev-gas/as-new

是否有一些解决方法?只是 ln -s prev-gas gas 安全吗?我有点希望这会在以后引起问题。 gcc 和 binutils 这两个版本不能一起构建吗?

最佳答案

这是我在 Ubuntu 14.04 Azure VM 上自行尝试后编辑的答案。

以下方法对我有用:

  • 构建并安装 binutils 2.26;为了本次讨论的目的, 假设它安装在/opt/gcc-5.3.0 中。
  • 使用 /root/objdir/../gcc-5.3.0/configure --prefix=/opt/gcc-5.3.0 在构建目录中配置 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 和构建目录 objdir 位于同一目录 水平。
  • objdir 构建目录中执行 make,然后执行 make install

验证新建的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 选项来 配置。如果你也想确保新构建的 binutils 用于构建 GCC,你可能希望将它们放在系统提供的工具之前的 PATH 中,或者你甚至可以重命名系统提供的工具以使其远离图片。

感谢您检查另一个邮件列表以验证一起构建 GCC 和 binutils 是行不通的,除非它们是从源代码管理中提取的,我想该选项在使用下载的 tarball 时不适用。总的来说,这是一个有趣的练习。

关于c++ - GCC 和 binutils build - C 编译器无法创建可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35778330/

相关文章:

c++ - 在 C++ 中是否可以进行热切的 thread_local 初始化?

c++ - Seek 不适用于使用 boost filtering_istreambuf 初始化的 std::istream

c++ - OpenGL 主循环绘制巨大的点 vector

double 类型的 C 函数有时在某些头文件中声明时可以工作

c++ - "Control reaches end on non-void function"with do { 返回结果; } 而(条件);

gcc - 将多个静态库合并为一个 GCC scons

c++ - 在 C++ 中打开 QFileDialog 时来自 KGlobal::locale 的错误

c - Mmap 不使用给定的地址

c 编程 10 个数字中最大的一个。我的代码有什么问题吗?我没有得到输出

c++ - 在 Linux 中使用 C++ 为 Windows CE 进行开发