使用scratchbox2建立交叉编译环境

使用scratchbox2建立交叉编译环境,使交叉编译不再烦人。。。。。

os:ubuntu 12.04.4 x64

1. 安装相关工具
sudo apt-get install debootstrap scratchbox2
sudo apt-get install qemu-user-static

mkdir rootfs  
cd rootfs

2. 下载debian 文件系统并安装
sudo debootstrap --verbose --arch mipsel --foreign stable `pwd` http://ftp.at.debian.org/debian

cp /usr/bin/qemu-mipsel-static  usr/bin

chroot . /bin/bash
/debootstrap/debootstrap --second-stage   

3. 建立交叉编译用环境
sb2-init ls1c /opt/CodeSourcery/mipsel-none-linux-gnueabi/bin/mipsel-none-linux-gnueabi-gcc
sudo sb2 或 sudo sb2 -t ls1c 

4. 例子
[SB2 simple ls1c ] root@vm ~ $ gcc hello.c
[SB2 simple ls1c ] root@vm ~ $ file a.out 
a.out: ELF 32-bit LSB executable, MIPSEL, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, BuildID[sha1]=0xd18141915ced466188d07dfd1a862a5d82d9de73, not stripped
[SB2 simple ls1c ] root@vm ~ $ ./a.out 
hello, world

5. 说明 
其中rootfs为目标板文件系统的目录,debootstrap会在里面安装相关的文件。
ls1c为自己取的名字,可以自己命名。gcc参数需填整完整的路径。
更详细的参数说明见sb2-init 帮助
如果觉得文件系统过大可以考虑用debian embedded 系统。

6. 参考文档:
http://www.cnblogs.com/qiaoqiao2003/p/3738552.html
http://blog.csdn.net/dotmonkey/article/details/6952460

 

http://bbs.loongnix.org/forum.php?mod=viewthread&tid=74477&extra=page%3D1

posted @ 2017-05-04 20:46  findumars  Views(330)  Comments(0Edit  收藏  举报