Cross Compile

From Rockchip open source Document
Revision as of 17:31, 15 December 2017 by Jacob (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Application Cross Compile

To cross compile debian application, we need debian stretch os and setup multiarch enviroment.
The following wiki will introduce you two ways to do it.



Docker is a open-source application container engin and we can use it to prepare a application cross compile environment.
To cross compile via docker, please refer to readme in docker-rockchip.




Install qemu

apt-get install qemu-user-static

Download debian arm image

sudo tar -xpf *.tar.gz

Download below script  and name it to

function mnt() {
    echo "MOUNTING"
    sudo mount -t proc /proc ${2}proc
    sudo mount -t sysfs /sys ${2}sys
    sudo mount -o bind /dev ${2}dev
    sudo mount --bind ${3} ${2}home/linaro/host

    sudo chroot   ${2}
function umnt() {
    echo "UNMOUNTING"
    sudo umount ${2}proc
    sudo umount ${2}sys
    sudo umount ${2}dev
    sudo umount ${2}home/linaro/host
if [ "$1" == "-m" ] && [ -n "$2" ] ;
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
    umnt $1 $2
    echo ""
    echo "Either 1'st, 2'nd or both parameters were missing"
    echo ""
    echo "1'st parameter can be one of these: -m(mount) OR -u(umount)"
    echo "2'nd parameter is the full path of rootfs directory(with trailing '/')"
    echo ""
    echo "For example: ch-mount -m /media/sdcard/"
    echo ""
    echo 1st parameter : ${1}
    echo 2nd parameter : ${2}

Copy qemu and network configure to rootfs

sudo cp -b /etc/resolv.conf binary/etc/resolv.conf
sudo cp /usr/bin/qemu-arm-static binary/usr/bin

Chroot to arm rootfs: -m binary/ {THE DIRECTORY  YOU WANT TO ACCESS IN CHROOT}
# change to a normal user. passwd:linaro
su linaro 
# install env
sudo apt-get update
sudo apt-get install gcc
# start build
make, cmake ......
# Don't forget to umount -u binary/



Build the chroot

sudo debootstrap --arch amd64 stretch ~/work/linaro-alip/cross-env

To enter

sudo chroot ~/work/linaro-alip/cross-env

add the following repository to etc/apt/source.list

deb-src stretch main
deb stretch main

prepare Multiarch

dpkg --add-architecture armhf
apt-get update
apt-get install curl
curl | apt-key add -
apt-get update
apt-get install  crossbuild-essential-armhf

get zlib source

tar -xvzf zlib-1.2.8.tar.gz
cd zlib-1.2.8

installing zlib's cross-dependencies

apt-get build-dep -a armhf zlib
apt-get install xxxx:armhf

configure the zlib library

CC=arm-linux-gnueabihf-gcc ./configure --prefix=/usr/

compile it


install it

mkdir out
make install DESTDIR=./out