利用crosstool-ng自动化编译交叉编译环境(转)

原文地址:http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/

 

A cross compiler is a compiler that runs on one platform/architecture but generates binaries for another platform/architecture. With devices like the Raspberry Pi, where you really don’t have much CPU or memory to work with, if you’re doing any heavy compiling (like when working on the kernel) a cross compiler is the only way to go. For example, I build all my Raspberry Pi kernels on my nice Sandy Bridge Xeon E3 home server where they compile in only a fraction of the time they would on the Pi.

 

While there are a lot of different methods for building cross-compilers, by far the quickest and easiest is to use crosstool-ng. This is a set of scripts that bring up a menuconfig-like interface to choose your compiler settings, then goes off and downloads what it needs, patches it, configures it, builds it and installs it all for you. Here’s how to get started:

  1. Download crosstool-ng from the project web site. I’ve used version 1.15.2 as that was the latest when I wrote this.
  2. Unpack the tarball and cd into the unpacked directory, then run ./configure --prefix=/opt/cross. You can pick somewhere else instead of /opt/cross but that’s where I like to keep it.
  3. Run make and sudo make install.
  4. Make sure /opt/cross/bin is in your $PATH.

Right, so that’s crosstool-ng installed and ready to build a toolchain for you. Next, to actually create your Raspberry Pi toolchain:

  1. Create a directory somewhere in your home directory that crosstool-ng will use as a staging ground. This will contain your toolchain configuration, downloaded files, and intermediary build results. This is not where your final toolchain will end up, and does take up quite a lot of space (3.5GB and up for me). cd into your chosen directory.
  2. Run ct-ng menuconfig. You should see the ct-ng configuration menu.
  3. Go into Paths and misc options. Enable Try features marked as EXPERIMENTAL. This is important.
  4. While you’re there you may want to change your Prefix directory. I like to put all my toolchains in /opt/cross/x-tools/${CT_TARGET} instead of ${HOME}/x-tools/${CT_TARGET}.
  5. Go back to the main menu and select Target options.
  6. Change the Target architecture to arm. Leave Endianness set to Little endian and Bitness set to 32-bit.
  7. Go back to the main menu and select Operating system (skip Toolchain options, the defaults are fine).
  8. Change Target OS to linux.
  9. Go back to the main menu and select Binary utilities.
  10. Change binutils version to 2.21.1a or whichever is the latest that isn’t marked as experimental. Probably unnecessary but I prefer this.
  11. Go back to the main menu and select C compiler.
  12. Enable the Show Linaro versions (EXPERIMENTAL) option.
  13. In the gcc version field, choose the linaro-4.6-2012.04 (EXPERIMENTAL) compiler. You’re free to choose a different one but I know this one works well. I do recommend the Linaro versions over the vanilla ones for the RPi.
  14. All the other settings are fine left at their default values. Exit the configuration tool and save your changes.
  15. Run ct-ng build.
  16. Go away and make a coffee, etc… This bit will take some time.
  17. You should end up with a freshly baked arm compiler ready for building kernels (and other things) for your Raspberry Pi in your Prefix directory you chose above.
  18. Just add your compiler directory to your $PATH and start compiling. If you used my preferred prefix directory, you would want to add /opt/cross/x-tools/arm-unknown-linux-gnueabi/bin.

转载于:https://www.cnblogs.com/tobeprogramer/p/4739164.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值