arm交叉变异环境安装

from:http://linux-sunxi.org/Toolchain

Toolchain

The toolchain is a set of binaries, system libraries and tools which allow you to build (in our case, cross-compile) u-boot and the kernel for a target platform. This will, to some limited extent, need to match the target rootfs. A large and incompatible change has taken place recently, through the Hard Float ABI. Now, two different debian and ubuntu ports are binary incompatible with each other.



Part of distributions

Ubuntu

Recent (from 12.04 on)

A complete cross toolchain is available as a package, just run:

apt-get install gcc-arm-linux-gnueabihf

Older

For older versions, you need to use an external repository.

add-apt-repository ppa:linaro-maintainers/toolchain
apt-get update
apt-get install gcc-arm-linux-gnueabihf

Debian

Details on Cross-development Toolchains for Debian are at the Debian Wiki.
Note: Debian now has cross-toolchains in the archive, superseding those at emdebian.org

Currently (December 2015) available for unstable and testing in the standard repositories.

Install Cross Compiler and build utilities:

dpkg --add-architecture armhf
apt-get update
apt-get install g++-arm-linux-gnueabihf

You might want additional tools for building a sunxi system that are not related to the cross-compiler:

apt-get install build-essential git debootstrap u-boot-tools device-tree-compiler

Fedora

A complete cross toolchain is available as a package, just run:

yum install gcc-arm-linux-gnu

Gentoo

The crossdev tool[1]is the standard way of dealing with crosscompilers in Gentoo. Command line options are used to specify any arbitrary mix of different versions of the kernel headers, glibc, binutils and gcc. You can also use the -S option instead (to pick whatever is considered to be stable at the moment), but in this case the crosscompiler will be also upgraded as part of the regular distribution updates, which might be a bit annoying.

ARM crosscompiler

Even though Gentoo normally uses armv7a-hardfloat-linux-gnueabi as the toolchain triplet on ARM, we can also use Debian alike arm-linux-gnueabihf variant in order to be able to use the compilation instructions from the linux-sunxi wiki as-is (without substituting the toolchain name).

emerge crossdev
crossdev --kernel =3.18 --libc =2.20-r2 --binutils =2.24-r3 --gcc =4.8.5 \
         --genv 'USE="-fortran -mudflap -nls -openmp multilib" EXTRA_ECONF="--with-cpu=cortex-a8 --with-float=hard"' -t arm-linux-gnueabihf
ARM64 crosscompiler
emerge crossdev
crossdev --kernel =3.18 --libc =2.21-r1 --binutils =9999 --gcc =4.9.3 \
         --genv 'USE="-fortran -mudflap -nls -openmp multilib -sanitize" EXTRA_ECONF="--enable-fix-cortex-a53-843419"' -t aarch64-linux-gnu

Note: binutils =9999 (fetch sources from git) should be replaced with =2.26 as soon as binutils 2.26 is added to portage. Such new binutils version is necessary for having a Cortex-A53 erratum 843419 workaround.

OpenRISC crosscompiler

If you have one of the Allwinner SoC variants with an additional OpenRISC core (for example A31 and H3 have it), then you might want to also build an OpenRISC crosscompiler too:

emerge crossdev
mkdir -p /etc/portage/patches/cross-or1k-elf/gcc-5.2.0
cd /etc/portage/patches/cross-or1k-elf/gcc-5.2.0
wget https://gist.githubusercontent.com/ssvb/28e22f4086af26ec9cd0/raw/8d3d091177156a92497f31de3bfb3d7da9e52649/0001-OpenRISC-support-for-GCC-5.2.0.patch
crossdev --binutils =2.25.1-r1 --gcc =5.2.0 --libc =2.2.0.20150423 \
         --genv 'USE="cxx multilib -fortran -mudflap -nls -openmp -sanitize"' \
         -s4 -t or1k-elf

Please note that the upstream GCC does not support OpenRISC yet, so the OpenRISC code is still brewing in https://github.com/openrisc/or1k-gcc.git and we can solve this problem by just providing a patch for GCC in the /etc/portage/patches directory.


  1. The Gentoo website has undergone a major overhaul as of April 2015. While a backup of the old content is still available, it seems to have left the Gentoo Embedded Handbook in a non-functional state. You can still find a copy via archive.org. The wiki article on Raspberry Pi Cross building might also be helpful.

Standalone

These standalone toolchains are big tarballs which come with everything you need.

Linaro toolchain

Download

Linaro has been very good at changing the location and availability of just about everything, making it very hard to keep a wiki up to date which refers to it. So the below download locations might be stale already.

Currently, the main selection page is here.

It lists the following toolchains:

When in doubt, try 4.7 first.

WARNING: Do not use the 4.8 gcc versions of the linaro toolchain to build legacy kernels (sunxi-3.4 etc.), those seem to have issues building the kernel. Use an earlier version instead. (TODO: Verify that this is still true today).

Usage

Take a gcc-linaro-<major>.<minor>-<year>.<month>.tar.xz file and untar it. You will find a bin directory in there. Temporarily add it to the environment you are building from:

export PATH="$PATH":/home/user/folder/gcc-linaro-arm-linux-gnueabihf-*_linux/bin/

no hardfloat?

Recent linaro toolchains are Hard Float (hf), this will be used throughout the wiki you see something like:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-

Replace arm-linux-gnueabihf- with arm-linux-gnueabi- if your are not using a hardfloat toolchain.

Code Sourcery

Another option is to install the Sourcery toolchain from Code Sourcery (now in Mentor Graphics). Download Code Sourcery G++ 2010 9-50https://sourcery.mentor.com/sgpp/lite/arm/portal/release1600 (official link, email registration required)

Direct link:https://netst.org/pub/linux/ARM/CodeSourcery/arm-2010.09-50-arm-none-linux-gnueabi.bin (unofficial link)


chmod +x arm-2010.09-50-arm-none-linux-gnueabi.bin
./arm-2010.09-50-arm-none-linux-gnueabi.bin


If you are using Ubuntu, you may need to switch to use bash shell (instead of dash shell)

sudo dpkg-reconfigure -plow dash      ( then choose [No], this changes from using dash shell to using bash shell )


It will now install CodeSourcery with a GUI installer

Follow default settings and do Next , Next, Next, etc…

It should install in: ~/CodeSourcery/ ( for example: /home/penguin/CodeSourcery/ )

Make sure the CodeSourcery binaries are added to your path (if your username is penguin, then this should be correct):

echo "export PATH=~/CodeSourcery/Sourcery_G++_Lite/bin:\${PATH}" >> ~/.bashrc
export PATH=~/CodeSourcery/Sourcery_G++_Lite/bin:$PATH   (or you can just spawn a new terminal window to update the path)
echo $PATH  (make sure your path is updated)

External links

交叉编译 Android 库,您需要使用 Android NDK 和 CMake。以下是一个简单的 CMakeLists.txt 文件示例,它可以用于交叉编译 Android 库: ```cmake cmake_minimum_required(VERSION 3.10) # 设置交叉编译工具链 set(CMAKE_SYSTEM_NAME Android) set(CMAKE_ANDROID_ARCH_ABI arm64-v8a) set(CMAKE_ANDROID_NDK /path/to/ndk) set(CMAKE_ANDROID_STL_TYPE c++_static) set(CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION clang) # 设置项目名称和语言 project(mylibrary CXX) # 添加源文件和头文件 add_library(mylibrary SHARED src/mylibrary.cpp) target_include_directories(mylibrary PRIVATE include) # 设置库的编译选项 target_compile_options(mylibrary PRIVATE -Wall -Wextra) # 设置链接选项 target_link_libraries(mylibrary log) ``` 在上面的示例中,您需要设置 `CMAKE_SYSTEM_NAME` 为 `Android`,并根据您的目标架构设置 `CMAKE_ANDROID_ARCH_ABI`。您还需要设置 Android NDK 的路径 `CMAKE_ANDROID_NDK`。如果您使用的是 C++ STL 库,则需要设置 `CMAKE_ANDROID_STL_TYPE`。最后,您需要设置 `CMAKE_ANDROID_NDK_TOOLCHAIN_VERSION`,以指定使用的编译器。 在添加源文件和头文件后,您可以设置编译选项和链接选项。在这里,我们使用 `target_compile_options` 和 `target_link_libraries` 分别设置编译选项和链接选项。 要交叉编译 Android 库,请使用以下命令: ```bash mkdir build cd build cmake -DCMAKE_TOOLCHAIN_FILE=../android.toolchain.cmake .. make ``` 其中,`android.toolchain.cmake` 是一个 CMake 工具链文件,它定义了交叉编译所需的编译器和库。您可以在 Android NDK 中找到该文件,路径为 `$ANDROID_NDK/build/cmake/android.toolchain.cmake`。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值