现在的位置: 首页 > 综合 > 正文

建立基于linux的MIPS交叉编译环境

2013年10月04日 ⁄ 综合 ⁄ 共 3385字 ⁄ 字号 评论关闭

建立基于linux的MIPS交叉编译环境
flw10000 发表于 2006-8-18 16:22:00
作者:冯磊 (flw10000) MAIL:flw10000 AT 163.com

更改记录:
2006 08 28 1>文章中有几个地方将安装目录误写为工具包的目录,大部分是在运行./configure时,另有两个cp命令,已更正!

 
 经过近一周的忙乎,把基于linux的MIPS交叉编译环境基本搭建成功,这里说"基本"搭建成功是因为环境虽然搭建好了,可以编译基于MIPS的可执
行文件了,但还没有在真正的MIPS环境下测试过,还有在编译的过程中出现了些问题,虽然解决了,也因没有在真正的MIPS环境下测试过,不知道会不会影
响正确的结果!
  我是在VMware中编译的,我的系统是RH8.0(2.4。18)
  用到的工具包:
  binutils-2.15,
  gcc-3.2.2,
  glibc-2.3.2,
  glibc-linuxthreads-2.3.2,
  linux-2.4.18,
  elf-machine-rela-mips.patch
  这里为什么要用这几个版本的工具包,主要是作者以前并没有做过交叉编译的环境,参考了网上的一些文章,而这些文章大部分用的是以上的版本!
  在编译时,硬盘最少应有不小于700M的空间,如果在编译过程中不打算删除源代码包的话,那至少应有不小于2G的空间.下面开始编译!
 
 我的工具包放在/mnt/sdb/mips/mips-toolchain/
,sdb是另挂的硬盘,安装的目录是/mnt/sdb/mips-toolchain/,这里两个目录很容易混淆,没有改的原因是由于在VMware中编
译,实在太慢了,下次一定整合理点!

  1>首先安装binutils,binutils是二近制工具包,网络上的定义:The
GNU Binutils is a collection of programming tools developed by the Free
Software Foundation for the manipulation of object code in various
object file formats. They are typically used in conjunction with GCC,
make and GDB.

#cd /mnt/sdb/mips/mips-toolchain/binutils-2.15
#./configure --prefix=/mnt/sdb/mips-toolchain --target=mipsel-linux
#make
#make install
    在编译完binutils以后,在/mnt/sdb/mips-toolchain/下生成了以下文件:
bin,info, lib, man, mipsel-linux, share.bin下生成13个可执行文件。

  2>接下来按装gcc,gcc需要编译两次,这次编译完只能支持C语言.

#export PATH=$PATH:/mnt/sdb/mips/mips-toolchain/bin //编译GCC时用到binutils-2.15生成的mipsel-linux-ar等.
#cd /mnt/sdb/mips/mips-toolchain/gcc-3.2.2
#./configure
--prefix=/mnt/sdb/mips-toolchain --target=mipsel-linux --with-newlib
--enable-languages=c --without-headers --disable-shared
--disable-threads
#make
#make install

    在第一次编译完gcc以后,在/mnt/sdb/mips-toolchain/下生成了以下文件:
在原来基础上又增加了include目录,且bin下又增加3个可执行文件。

3>接下来配置内核,目的是得到asm的链接和version.h头文件,然后将linux/include/中的asm和linux目录整个拷贝到/mnt/sdb/mips-toolchain/include目录下面
#cd /mnt/sdb/mips/mips-toolchain/linux/include
#ln -s asm-mips asm
#cd ../
#make menuconfig随便配置一下,因为我们并不需要编译内核,只是得到version.h就可以了.
#cp include/asm-mips /mnt/sdb/mips-toolchain/linux/include/asm -R
#cp include/linux /mnt/sdb/mips-toolchain/linux/include/linux-R

4>
在下来就是编译glibc了,建立glibc-mips目录,在glibc-2.3.2和glibc-mips目录下面分别解压缩glibc-
linuxthreads-2.3.2.tar.gz,glibc-2.3.2需要elf-machine-rela-mips.patch补丁

#cd /mnt/sdb/mips/mips-toolchain/glibc-2.3.2
#patch -p1 < elf-machine-rela-mips.patch
#cd ..
#mkdir glibc-mips //临时目录
#cp glibc-linuxthreads-2.3.2/* glibc-mips/ -R
#cp glibc-linuxthreads-2.3.2/* glibc-2.3.2/ -R
#mkdir /mnt/sdb/mips-toolchain/mips-glibc //安装目录
#cd glibc-mips
#../glibc-2.3.2/configure --host=mipsel-linux --enable-add-ons=linuxthreads --disable-sanity-checks
#make
#make install_root=/mnt/sdb/mips-toolchain/mips-glibc install

/mnt/sdb/mips-toolchain/mips-glibc/usr/local中的lib和include目录拷贝到/mnt/sdb
/mips-toolchain/mipsel-linux中,并将lib目录中的文件拷贝到/usr/local/lib中,为编译完整的gcc做准备

5>最后一步,配置编译完整的gcc,这次编译完的gcc将支持c++.
#cd /mnt/sdb/mips/mips-toolchain/gcc-3.2.2
#./configure
--prefix=/mnt/sdb/mips-toolchain --target=mipsel-linux --enable-shared
--enable-threads
--with-headers=//mnt/sdb/mips-toolchain/mipsel-linux/include
#make
在这里发生了一个错误
checking whether we are using GNU C... (cached) yes
checking
whether /mnt/clfs/xxx/gcc-3.2.2/gcc/xgcc -B/mnt/clfs/xxx/gcc-3.2.2/gcc/
-B/mnt/clfs/mips-toolchain/mipsel-linux/bin/
-B/mnt/clfs/mips-toolchain/mipsel-linux/lib/ -isystem
/mnt/clfs/mips-toolchain/mipsel-linux/include accepts -g... (cached) yes

configure: error: libffi has not been ported to mipsel-unknown-linux-gnu.
make: *** [configure-target-libffi] Error 1
搜了一下,如果交叉编译环境只用来编译c语言,libff是i没有用的,所以手工更改了Makefile中libffi相关的部分.
#make install

  
好了,到这里完整的mips toolchain就搭建完成了 !

抱歉!评论已关闭.