本文拷贝编辑如下链接制作而成,本人只起到编辑作用,只是为了便于自己理解,按照自己的习惯编排和收集整理:
http://forum.wdlxtv.com/viewtopic.php?f=43&t=3108
http://blog.csdn.net/langxing0508/article/details/5861574
http://archive.cnblogs.com/a/2285209/
http://biffengineering.com/wiki/index.php?title=HowToSetupCrossCompileEnvironment
http://plugcomputer.org/plugwiki/index.php/Scratchbox2_based_cross_compiling
http://thekingisgone.72pines.com/category/toolchain/page/2/
http://www.mcuol.com/Tech/116/17113.htm
sbox2简介
scratchbox2是scratchbox1的第二版。但是第二版完全舍弃的第一版,在使用上第二版比第一版方便、易用很多。
2009年4月,Scratchbox2正式发布,2010年3月,Nokia正式接手scratchbox2 的维护工作。Tizen项目也用Scratchbox2作为交叉编译环境。
Scratchbox2的使用要配合qemu、交叉工具链和目标平台的根文件系统来使用。
qemu是目标平台的CPU虚拟机,如ARM的虚拟机是qemu-arm。交叉工具链可以是自己制作的,或者从CodeSourcery网站等下载的交叉编译工具链。根文件系统是目标平台的根文件系统。
安装scratchbox2
1) 在ubuntu10.04下可以使用apt-get install安装scratchbox2
$ sudo apt-get install scratchbox2
2)由源代码编译
git clone git://gitorious.org/scratchbox2/scratchbox2.git sbox2
git clone git://gitorious.org/scratchbox2/scratchbox2.git sbox2
cd sbox2
./autogen.sh
./configure --prefix=/usr/local
make
sudo make install
请参考
http://biffengineering.com/wiki/index.php?title=HowToSetupCrossCompileEnvironment
安装qemu
1) 在ubuntu10.04下可以使用apt-get install安装qemu-arm。其中qemu-arm包含在qemu-kvm-extras中,安装如下:
$ sudo apt-get install qemu-kvm-extras
2)由源代码编译请参考
git clone git://git.qemu.org/qemu.git
./configure --prefix=/usr/local/ --target-list=arm-linu-user,arm-softmmu
make&make install
http://biffengineering.com/wiki/index.php?title=HowToSetupCrossCompileEnvironment
安装交叉编译工具链
如果编译目标为ARM的CPU,CodeSourcery的工具链是不错的选择:
http://www.codesourcery.com/gnu_toolchains/arm/download.html
注意,Scratchbox1的工具链不能在Scratchbox2上用。
在CodeSourcery的工具链的arm-2008q3/arm-none-linux-gnueabi/libc中,可以找到最基本的编译工具,将其复制到buildroot中。
为了完成Scratchbox2的安装,还必须要执行:
$ mkdir $HOME/buildroot
$ cd $HOME/buildroot
$ cp -a $HOME/arm-2008q3/arm-none-linux-gnueabi/libc/{lib,etc,usr} .
$ $HOME/sb2/bin/sb2-init my_target arm-none-linux-gnueabi-gcc
这将自动生成目标系统的配置文件,其间sb2-build-libtool脚本将为编译器设置好用的libtool.
If you using Ubuntu 11.10, plz use the following
sudo add-apt-repository "deb http://www.emdebian.org/debian/ unstable main"
apt-get install g++-4.4-arm-linux-gnueabi
apt-get install build-essential debootstrap fakeroot
If you're running Ubuntu 10.04, there are backports of this cross-toolchain in a PPA maintained by Linaro: sudo add-apt-repository ppa:linaro-maintainers/toolchain sudo apt-get update sudo apt-get install gcc-arm-linux-gnueabi
apt-get install build-essential debootstrap fakeroot
准备根文件系统
export BUILDROOT=/home/{user}/buildroot
方法1: 手动创建
将工具链中的相关文件都复制到正确的地方。根文件系统的必要内容是在lib目录下必须有C动态库。
如下,建立根文件系统和拷贝必要C库。
$ cd $BUILDROOT $ mkdir bin dev etc lib sbin usr tmp proc sys $ cp -a ./toolchain/arm-eabi-4.4.3/arm-linux/lib/* lib/
这里以
$BUILDROOT
作为目标平台的根目录,并且拷贝了arm-eabi-4.4.3工具链的C库到这个根目录下。
方法2: 利用debootstrap创建
fakeroot /usr/sbin/debootstrap --verbose --arch armel --foreign squeeze ./arm http://ftp.at.debian.org/debian
配置sb2环境
以上3步完成之后,下面就可以使用安装的scratchbox2配置目标平台的模拟环境。配置模拟环境使用的是sb2-init工具,如下:
$ sb2-init -c qemu-arm ARM3.4.5 arm-linux-gnueabi-gcc
其中,“-c qemu-arm ”表示使用qemu-arm虚拟机;“ARM3.4.5”表示这次配置的模拟环境的名称;“./toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc ”表示在这个模拟环境中gcc对应的程序是哪个。
第一次配置时,会先下载安装libtool,配置成功,出现下面的提示。
sb2-init completed successfully, have fun!
编译libtool issue
/usr/local/bin/sb2-build-libtool
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.
If you meant to cross compile, use `--host'.
See `config.log' for more details.
需要更改/usr/local/bin/sb2-build-libtool 增加'--host=arm-linux '参数
安装必要的程序到$BUILDROOT目录
cd bash-4.1/
sb2 ./configure --prefix=$BUILDROOT
sb2 make
sb2 make install
cd make-3.82/
sb2 ./configure --prefix=$BUILDROOT/usr
sb2 make
sb2 make install
cd coreutils-8.8/
sb2 ./configure --prefix=$BUILDROOT/usr
sb2 make
sb2 make install
cd $BUILDROOT/bin
ln -s ../usr/bin/mkdir
cd binutils-2.21/
sb2 ./configure --prefix=$BUILDROOT/usr
sb2 make
sb2 make install
cd gawk-3.1.8/
sb2 ./configure --prefix=$BUILDROOT/usr
sb2 make
sb2 make install
cd gcc-4.3.2/
tar xjf mpfr-2.4.2.tar.bz2
mv mpfr-2.4.2 mpfr
tar xjf gmp-5.0.1.tar.bz2
mv gmp-5.0.1 gmp
tar xzf mpc-0.8.2.tar.gz
mv mpc-0.8.2 mpc
mkdir build
cd build
[source toolchain.env here]
../configure --target=arm-linux --host=arm-linux --build=i686 --prefix=/usr --enable-languages=c --disable-libmudflap
make
make install prefix=$BUILDROOT/usr
使用模拟器
hello.c
#include <stdio.h> int factorial(int n) { if (n == 0) return 1; return n * factorial (n - 1); } int main () { int i; int n; for (i = 0; i < 10; ++i) { n = factorial (i); printf ("factorial(%d) = %d\n", i, n); } return 0; }
模拟环境配置好后,就可以在任何地方使用sb2来编程程序,如要交叉编译hello.c程序:
$ sudo sb2 gcc hello.c -o hello
查看编译出来的hello程序信息,可以看到在sbox2模拟环境中,使用gcc编译的程序是基于arm平台的,如下:
$ file hello
hello: ELF 32-bit LSB executable, ARM, version 1, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped
可以在模拟环境中运行程序:
$ sudo sb2 ./hello
hello farsight!
问题
http://web.archiveorange.com/archive/v/bWlyQ7E68NYX2szvFfzm
综述
在sbox2配置的模拟环境中编译一些利用autotool发布的开源软件比普通的交叉编译方法方便很多。如SDL、ffmpeg、vlc等软件在这个模拟器下编译,在配置时只需使用 “ –prefix ”选项指定安装路径就可以了。