在amd64上编译gcc,以便在i686上运行,并且目标是mips [英] Compile gcc on amd64, for running on i686, and target is mips

查看:308
本文介绍了在amd64上编译gcc,以便在i686上运行,并且目标是mips的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为MIPS目标编译gcc和binutils.我正在64位(amd64)机器上工作.并想要获得能够在i686(而非amd64)架构上运行的二进制文件?我应该如何构筑gcc?

I want to compile gcc and binutils for MIPS target. I am working on 64-bit (amd64) machine. And want to obtain binary which is able to run on i686 (not amd64) arhitecture? How should I condigure and build gcc?

如果我将--host = i686-linux-gnu添加到./configure脚本中,那么它将抱怨缺少i686-xxxx工具.

If I am adding --host=i686-linux-gnu to ./configure script, then it complains on absence of i686-xxxx tools.

如果我添加CFLAGS = -m32,则由于以下错误,我可以构建binutils,但不能构建gcc:

If I am adding CFLAGS=-m32, then I can build binutils, but not gcc, because of following error:

 g++   -g -O2 -DIN_GCC  -DCROSS_DIRECTORY_STRUCTURE  -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -DGENERATOR_FILE -static-libstdc++ -static-libgcc  -o build/genconstants \
build/genconstants.o build/read-md.o build/errors.o ../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a
/usr/bin/ld: i386 architecture of input file `../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a(concat.o)' is incompatible with i386:x86-64 output
/usr/bin/ld: i386 architecture of input file `../build-x86_64-unknown-linux-gnu/libiberty/libiberty.a(fopen_unlocked.o)' is incompatible with i386:x86-64 output
...

推荐答案

我找到了解决方案,需要在make命令行中传递以下环境变量:

I found solution, need to pass following environment variables in make command line:

CC="gcc -m32" CXX="g++ -m32" LDFLAGS=-m32

仅此而已. CFLAGS的导出将不起作用.您需要导出CFLAGS,CXXFLAGS和LDFLAGS,但此处存在一些陷阱:

Thats all. Exporting of CFLAGS will not work. You need to export CFLAGS, CXXFLAGS and LDFLAGS, but few pitfalls exists here:

  1. CFLAGS = -m32也将导出到MIPS编译器,该编译器不了解-m32标志(构建libgcc时失败);
  2. CXXFLAGS = -m32对gcc使用的库有影响,并且配置脚本失败;
  3. 您可以改用ALL_CFLAGS,但不适用于gcc本身和libcpp.

另请参阅类似的问题:建筑物32来自64位源代码的GCC:链接问题

See also similar question: Building 32 bit GCC from source on 64 bit: linking issue

这篇关于在amd64上编译gcc,以便在i686上运行,并且目标是mips的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆