Building an ARM GCC Toolchain from Source

本教程提供在Windows和Linux环境下从源码构建GCC交叉编译工具链的详细步骤。涵盖所需软件安装、配置及编译过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Step by step guide on building a GCC cross-compilation toolchain from source on Windows and Linux

While we'd strongly recommend starting with one of the precompiled GNU GCC toolchains available for ARM such asCodeSourcery G++ Lite orYagarto(seeSetting up a GCC Development Environment for the Cortex M0/M3 for more information), using a precompiled toolchain leaves you at the mercy of someone else's whims and fancies about what features to include, what libraries to use, etc. Depending on precompiled toolchains also means that you're depending on their authors to regularly update them when new releases of GCC become available.

This tutorial came to life precisely because of a situation like that: GCC 4.5.0 is the first version to have official support for the ARM Cortex-M0core, but unfortunatelyall the precompiled toolchains at the time this article was written were still based on GCC 4.4.x.Roel Verdult (from libnfc.org) came to the rescue and provided this step-by-step tutorial on buildingGCCfrom source in both Linux and Windows for us. If you need to build your own toolchain as well, this tutorial should at least get you well on your way.

Linux


Building GCC under Linux requires less steps than in Windows since a number of required packages are typically already installed on most Linux distributions or they can be easily installed from pre-compiled binaries. GCC compile times are also generally a lot faster under Linux than in Windows, which is helpful for packages as 'large' as a custom GNU GCC for ARM toolchain. That said ... the entire build process will probably still take about an hour on most machines.

This tutorial was written and tested for Ubuntu 10.10, but should be easily adaptable to most modern Linux distributions. The build script currently builds GCC 4.5.2, Binutils 2.21, Newlib 1.19 and GDB 7.2.

Step 1: Install build tools and packages

From the command-prompt, enter the following command:
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libmpc-dev
sudo apt-get install zlib1g-dev
sudo apt-get install texinfo
sudo apt-get install libncurses5-dev

Step 2: Build the GCC Toolchain

Download summon-arm-toolchain.tar.gz, decompress it and run it using the following commands:
wget http://www.microbuilder.eu/Files/Tutorials/summon-arm-toolchain.tar.gz
tar -xvzf summon-arm-toolchain.tar.gz
sh summon-arm-toolchain.sh ~/ arm-none-eabi

Step 3: Add the GCC Toolchain to PATH

Next you need to add the location of the compiled binaries to your path variable with the following command:
$ echo "PATH=$PATH:~/arm-none-eabi/bin" >> .bashrc
Note: You will need to restart the console for these changes to take effect.

Windows


Building GCC under Windows is a little bit more complicated than in Linux, since a number of packages need to be installed beforehand. This guide will help you install and configure the required software packages to be able to build a GCC cross-compiling toolchain for ARM.

Note for Windows Users: It will take 90 minutes or more under Windows to build all the tools and libraries required for a GNU GCC cross-compiling toolchain for ARM. To make the installation process as easy as possible and avoid having to restart the process, we strongly recommend using the default folders for MINGW and MSYS, since changing them from "<drive>:\MINGW" and "<drive>:\MSYS" will require extra steps that aren't documented here.

Step 1: Install MinGW and MSYS Base System

Before you can do anything useful, you will need to download Minimalist GNU for Windows (MinGW) andMSYS Base System with GNU Utilities (MSYS), both of which are available from theMinGW SourceForge download page. You can also download the files directly with the following links (which were the most recent versions at the publication of this article, 19 April 2010):

Step 2: Download GNU wget

Next you need to download wget (a non-interactive network retriever) using the link below, and place the executable file in the "msys\1.0\bin" folder:

  • Direct Download: wget

Step 3: Load the MSYS Environment and Start Building

Next you need to start the MSYS environment by selecting "Start -> Programs -> MinGW -> MSYS -> MSYS" in the start menu. (The menu options may vary slightly depending on which version of Windows you are using, and how you're start menu is configured.). This UNIX console will be used to build the necessary packages as well as the GNU GCC ARM Toolchain:

Mount MinGW in MSYS
To access MinGW from MSYS, you will need to configure MSYS to associate "/mingw" with the MinGW installation path (presumably "c:\mingw" if you used the default settings during installation). This can be done with the following command:
mount c:/mingw /mingw
Build GMP (GNU Multiple Precision Arithmetic Library)
$ wget ftp://ftp.gmplib.org/pub/gmp-5.0.1/gmp-5.0.1.tar.gz
$ tar -xvzf gmp-5.0.1.tar.gz
$ cd gmp-5.0.1
$ ./configure --prefix=/mingw
$ make
$ make install
$ cd ..
Build MPFR (Multi-Precision Floating Point Library)
$ wget http://www.mpfr.org/mpfr-current/mpfr-2.4.2.tar.gz
$ tar -xvzf mpfr-2.4.2.tar.gz
$ cd mpfr-2.4.2
$ ./configure --prefix=/mingw
$ make
$ make install
$ cd ..
Build MPC (Multi-Precision Complex Arithmetic Library)
$ wget http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz
$ tar -xvzf mpc-0.8.1.tar.gz
$ cd mpc-0.8.1
$ ./configure --prefix=/mingw
$ make
$ make install
$ cd ..

Step 4: Build GNU GCC ARM Toolchain

Last, you need to download a simple script file that will handle the compilation of the GNU GCC ARM Toolchain (GCC 4.5.0, Newlib 1.18.0, GDB 7.1 and Binutils 2.20.1). Download the following file, and unzip it in the "<drive>:\msys\1.0\home\<username>\" folder:

Build GNU GCC
$ sh summon-arm-toolchain.sh ~ arm-none-eabi

Step 5: Adding the Environment Variables in Windows

In order to access the newly built GCC toolchain from the command-prompt, you will need to add the appropriate paths to the Windows "path". You can do this using the following steps:

  • Right-click on My Computer and select Properties from the popup-menu
  • Switch to the Advanced tab
  • From there, select the Environment Variables button at the bottom
  • Find the Path system variable and click the Edit button

"Path" Environment Variables
C:\msys\1.0\home\<username>\arm-none-eabi\bin;C:\msys\1.0\bin\
You may need to reset your system in order for the new path variables to take effect. At this point, you should be able to build makefile-based projects from the command-line using "make" with the new GNU GCC ARM cross-compiling toolchain!
<think>好的,我现在需要解决用户在Ubuntu上安装arm-none-eabi-gcc时遇到的“E: Unable to locate package”错误。首先,我应该回忆一下自己之前处理类似问题的经验,或者查找相关的资料。 根据用户提供的引用内容,引用[1]提到遇到无法定位包时,先执行sudo apt-get update更新软件源列表,如果不行再尝试升级,或者使用aptitude安装。引用[2]和[3]则是在安装gcc和相关工具时遇到的问题,可能涉及软件源配置的问题。 首先,用户尝试安装的是arm-none-eabi-gcc,这个包可能不在Ubuntu默认的软件源中。常见的解决步骤应该是: 1. 更新软件包列表:sudo apt update。这可以确保本地缓存是最新的,有时候旧的缓存里没有某些包的信息。 2. 检查包名称是否正确。有时候包的名字可能有不同的拼写,比如是否带有连字符或者其他后缀。比如arm-none-eabi-gcc可能属于某个特定的工具链仓库。 3. 如果包确实不在默认源中,可能需要添加第三方仓库。例如,ARM官方可能提供自己的APT仓库,或者通过PPA添加。 4. 安装失败后,尝试使用aptitude,因为它有时会建议解决方案,比如安装其他可能的包或启用某些仓库。 5. 另外,也可以考虑手动下载安装包进行安装,或者使用其他包管理工具,比如snap。 接下来需要确认arm-none-eabi-gcc的正确来源。通常,这个包属于gcc-arm-embedded工具链。在较新的Ubuntu版本中,可能需要添加特定的PPA或者从ARM官网下载。比如,用户可能需要添加PPA:team-gcc-arm-embedded/ppa,但需要先确认这个PPA是否存在以及是否支持当前的Ubuntu版本。 步骤可能包括: - 添加PPA:sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa - 再次更新:sudo apt update - 安装:sudo apt install gcc-arm-embedded 如果PPA不可用或已经过时,可能需要从ARM官方网站下载工具链,解压并添加到PATH环境变量中。 另外,用户可能没有启用multiverse仓库或者其他必要的组件。检查/etc/apt/sources.list中是否启用了所有必要的仓库。 还有一种可能是该包在Ubuntu的软件源中名称不同,例如叫做gcc-arm-none-eabi,而不是arm-none-eabi-gcc。用户需要确认正确的包名,可以通过apt search arm-none-eabi来搜索相关的包。 总结可能的解决步骤: 1. 更新软件源列表 2. 检查包名称是否正确 3. 添加正确的软件仓库(PPA) 4. 再次更新并安装 5. 使用aptitude或手动安装 需要确保每一步都给出清晰的指令,并提醒用户注意可能的问题,比如PPA不支持当前系统版本,或者需要手动下载工具链。同时,引用相关的引用内容,比如引用[1]提到的update和upgrade步骤,引用[3]中的安装命令可能需要调整包名。</think>要解决在Ubuntu上安装`arm-none-eabi-gcc`时出现`E: Unable to locate package`错误的问题,可按照以下步骤操作: --- ### 1. **更新软件包列表** 首先确保本地软件源列表是最新的: ```bash sudo apt-get update ``` 此操作会同步远程仓库的包信息到本地,可能解决因缓存过时导致的包未找到问题[^1]。 --- ### 2. **验证包名称是否正确** Ubuntu官方仓库中`arm-none-eabi-gcc`的包名通常为`gcc-arm-none-eabi`。尝试以下命令: ```bash sudo apt install gcc-arm-none-eabi ``` 若成功,则原问题由包名拼写错误导致。 --- ### 3. **添加第三方软件源** 若默认仓库未包含该工具链,需手动添加ARM官方支持的仓库: 1. 添加仓库并更新: ```bash sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update ``` 2. 再次尝试安装: ```bash sudo apt install gcc-arm-none-eabi ``` --- ### 4. **使用aptitude安装** 若仍失败,可尝试`aptitude`(需先安装): ```bash sudo apt install aptitude sudo aptitude install gcc-arm-none-eabi ``` `aptitude`会提供备选解决方案,例如建议启用特定仓库或安装替代包。 --- ### 5. **手动安装ARM工具链** 若以上方法无效,从ARM官网下载预编译工具链: 1. 访问[ARM官方下载页面](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads),选择适用于Linux的版本。 2. 解压并添加到环境变量: ```bash tar -xjf gcc-arm-none-eabi-xxx.tar.bz2 sudo mv gcc-arm-none-eabi-xxx /opt/ echo 'export PATH=$PATH:/opt/gcc-arm-none-eabi-xxx/bin' >> ~/.bashrc source ~/.bashrc ``` --- ### 6. **检查系统架构兼容性** 确保系统架构(如64位)与工具链兼容。若需32位支持,安装依赖库: ```bash sudo apt install lib32z1 lib32ncurses5 ``` --- ### 总结 1. 优先通过**修正包名**(`gcc-arm-none-eabi`)和**更新仓库**解决[^1]。 2. 若仓库缺失,使用**手动安装**或添加**第三方PPA**。 3. 对于嵌入式开发,手动安装官方工具链通常是更稳定的选择。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值