我可以使用X64编译gcc for ARM吗? [英] Can I build gcc for ARM with an X64 one?

查看:571
本文介绍了我可以使用X64编译gcc for ARM吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个明确的答案,因为这仍然不清楚我,我不能找到一个明确的答案在文档的任何地方。

I need a definitive answer because this is still unclear to me and I can't find an explicit answer anywhere in the docs.

假设我有一个工作的 gcc 工具链

Assuming that I have a working gcc toolchain where

host    x86_64-linux-gnu
target  x86_64-linux-gnu


b $ b

,问题是我可以配置和建立 gcc 吗?

host    x86_64-linux-gnu
build   x86_64-linux-gnu
target  arm-gnu-eabi

为什么我想回答这个问题的原因是关于我是否应该花时间为我的库尝试不同的配置,以及是否或是否脚本用于构建 gcc 能够进行一些隐式阶段1构建,这可能潜在地在这个x64上为我暂时引导ARM编译器,所以我可以生成工具链需要我想要的目标。

The reason why I would like an answer on this is about whether or not I should spend time trying different configurations for my libraries and whether or whether or not the scripts used to build gcc are capable of some implicit stage 1 build that can potentially bootstrap an ARM compiler for me temporarily on this x64, so I can generate the toolchain that I need for the target that I want .

推荐答案


X64一个?

是的,可以。我已经在我的博客帖子

Yes, you can. I have described this process for a suse linux host development system in a blog post of mine.

===================== ==================================================== =============
我要复制这里的步骤:

================================================================================== I'm going to replicate the steps here:

1。确保有必要的标题&库已安装

我使用YAST的安装软件功能安装以下软件包,这些软件包是完成所有构建步骤包名称,选择并接受):

I have used YAST's 'Install Software' feature, to install the following packages that will be necessary to complete all the build steps (just search for the package names, select and accept):


  • gmp-devel

  • mpfr-devel

  • mpc-devel

  • texinfo

  • ncurses-devel

  • termcap

  • gmp-devel
  • mpfr-devel
  • mpc-devel
  • texinfo
  • ncurses-devel
  • termcap

2。创建目录骨架

cd ~
mkdir arm-none-eabi arm-none-eabi-src
cd arm-none-eabi
mkdir src build
cd ~/arm-none-eabi-src
mkdir src build






3。下载源程序包并解压缩它们

我在这里使用 gcc-4.7.1 ,但是相同的过程当然适用于较新版本的GCC。

I'm using gcc-4.7.1 here, but the same process will of course apply for newer versions of GCC.

cd ~/arm-none-eabi-src/src

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.1/gcc-4.7.1.tar.bz2
wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2
wget ftp://ftp.gnu.org/gnu/gdb/gdb-7.4.tar.bz2
wget ftp://sources.redhat.com/pub/newlib/newlib-1.20.0.tar.gz

tar -xf gcc-4.7.1.tar.bz2
tar -xf binutils-2.22.tar.bz2
tar -xf gdb-7.4.tar.bz2
tar -xf newlib-1.20.0.tar.gz






4。构建binutils

cd ~/arm-none-eabi-src/build
mkdir binutils-2.22
cd binutils-2.22
../../src/binutils-2.22/configure \
  --target=arm-none-eabi \
  --prefix=$HOME/arm-none-eabi \
  --with-cpu=cortex-m3 \
  --with-no-thumb-interwork \
  --with-mode=thumb
make all install
export PATH="$PATH:$HOME/arm-none-eabi/bin"






5。构建GCC(第1部分)

cd ~/arm-none-eabi-src/build
mkdir gcc-4.7.1
cd gcc-4.7.1
../../src/gcc-4.7.1/configure --target=arm-none-eabi \
  --prefix=$HOME/arm-none-eabi --with-cpu=cortex-m3 \
  --with-mode=thumb --disable-multilib \
  --with-no-thumb-interwork \
  --enable-languages="c,c++" --with-newlib \
  --with-headers=../../src/newlib-1.20.0/newlib/libc/include
make all-gcc install-gcc

--enable-cxx-flags配置选项可能另外用于控制libstdc ++(包括在此步骤中)的构建标志:

The --enable-cxx-flags configure option might be additionally used to control the build flags of the libstdc++ (included in this step):

--enable-cxx-flags='-fno-exceptions \
    -ffunction-sections -fno-omit-frame-pointer'

一般来说,应该使用相同的C ++编译标志,因为它们会在构建目标代码时出现。

In general the same C++ compile flags should be used as they'll appear when building the intended target code.

6。使用交叉编译器(Part2)构建GCC newlib

cd ~/arm-none-eabi-src/build
mkdir newlib-1.20.0
cd newlib-1.20.0
../../src/newlib-1.20.0/configure --target=arm-none-eabi \
  --prefix=$HOME/arm-none-eabi --disable-multilib \
  --disable-newlib-supplied-syscalls
make all install

有关 - disable-newlib- -syscalls 选项:

禁用默认的newlib系统调用桩实现通常是一个好主意,当你打算编译目标,而不使用像操作系统的linux,或没有操作系统。它将留给您未使用的存根函数的链接器错误,你需要为newlib提供。
删除该选项仍然可以使用你自己的实现来覆盖newlib提供的stub。

A note about the --disable-newlib-supplied-syscalls option:
Disabling the default newlib syscall stub implementation is generally a good idea when you intend to compile for targets without using a linux like operating system, or no OS at all. It will leave you with linker errors on unimplemented stub functions you'll need to provide for newlib. Removing the option will still enable you to override the newlib provided stubs with your own implementations.

但是,当你计划使用交叉工具链与CMake,你应该省略这个选项。 CMake使用指定的编译器定义(例如从toolchain.cmake文件)进行一些基本测试,如果没有提供默认的存根实现,它会失败。

Though, when you plan to use the cross-toolchain in conjunction with CMake, you should omit this option. CMake does some basic tests using the specified compiler definitions (e.g. from a toolchain.cmake file), that'll fail without the default stub implementations supplied.

7。完成安装GCC

cd ~/arm-none-eabi-src/build/gcc-4.7.1
make all install






8。构建GDB

cd ~/arm-none-eabi-src/build
mkdir gdb-7.4
cd gdb-7.4
../../src/gdb-7.4/configure --target=arm-none-eabi \
  --prefix=$HOME/arm-none-eabi
make all install






UPDATE

对于GCC 4.8.2也是如此。


UPDATE
The same works pretty well for GCC 4.8.2 also.

这篇关于我可以使用X64编译gcc for ARM吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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