敬请阅读

ubuntu 20.04 搭建mips编译环境和zlib库

2020年6月5日 分类:Linux 作者:tetsai

声明:本页面已按照MIP设计规范为移动端进行优化,可能存功能或内容缺失,完整版可以点此跳到底部然后查看.

tetsai

原创声明

本文由tetsai原创,转载请注明来源

网上都是老包了,还有一些奇怪的源,简直误人子弟啊!难道这里的特色就是转来转去?

mips环境搭建

搜索包


$ apt search mips-linux
正在排序... 完成
全文搜索... 完成  
binutils-mips-linux-gnu/focal,now 2.34-5ubuntu1cross6ubuntu1 amd64 [已安装,自动]
  GNU binary utilities, for mips-linux-gnu target

binutils-mips-linux-gnu-dbg/focal 2.34-5ubuntu1cross6ubuntu1 amd64
  GNU binary utilities, for mips-linux-gnu target (debug symbols)

cpp-10-mips-linux-gnu/focal,now 10-20200324-1ubuntu1cross1 amd64 [已安装,自动]
  GNU C preprocessor

cpp-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU C preprocessor

cpp-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU C preprocessor (cpp) for the mips architecture

g++-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU C++ compiler (cross compiler for mips architecture)

g++-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU C++ compiler (multilib support) (cross compiler for mips architecture)

g++-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU C++ compiler (cross compiler for mips architecture)

g++-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU C++ compiler (multilib support) (cross compiler for mips architecture)

g++-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU C++ compiler for the mips architecture

g++-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU C++ compiler for the mips architecture

gcc-10-mips-linux-gnu/focal,now 10-20200324-1ubuntu1cross1 amd64 [已安装]
  GNU C compiler (cross compiler for mips architecture)

gcc-10-mips-linux-gnu-base/focal,now 10-20200324-1ubuntu1cross1 amd64 [已安装,自动]
  GCC, the GNU Compiler Collection (base package)

gcc-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU C compiler (multilib support) (cross compiler for mips architecture)

gcc-10-plugin-dev-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  Files for GNU GCC plugin development.

gcc-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU C compiler (cross compiler for mips architecture)

gcc-9-mips-linux-gnu-base/focal 9.3.0-10ubuntu1cross1 amd64
  GCC, the GNU Compiler Collection (base package)

gcc-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU C compiler (multilib support) (cross compiler for mips architecture)

gcc-9-plugin-dev-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  Files for GNU GCC plugin development.

gcc-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU C compiler for the mips architecture

gcc-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU C compiler for the mips architecture

gccgo-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Go compiler

gccgo-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Go compiler (multilib support) (cross compiler for mips architecture)

gccgo-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Go compiler

gccgo-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Go compiler (multilib support) (cross compiler for mips architecture)

gccgo-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  Go compiler (based on GCC) for the mips architecture

gccgo-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  Go compiler (based on GCC) for the mips architecture

gdc-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU D compiler (version 2) (cross compiler for mips architecture)

gdc-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU D compiler (version 2, multilib support) (cross compiler for mips architecture)

gdc-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU D compiler (version 2) (cross compiler for mips architecture)

gdc-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU D compiler (version 2, multilib support) (cross compiler for mips architecture)

gdc-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU D compiler (based on GCC) for the mips architecture

gdc-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU D compiler (based on GCC) for the mips architecture

gfortran-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Fortran compiler

gfortran-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Fortran compiler (multilib support) (cross compiler for mips architecture)

gfortran-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Fortran compiler

gfortran-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Fortran compiler (multilib support) (cross compiler for mips architecture)

gfortran-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Fortran 95 compiler for the mips architecture

gfortran-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Fortran 95 compiler for the mips architecture

gm2-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Modula-2 compiler (cross compiler for mips architecture)

gm2-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Modula-2 compiler (cross compiler for mips architecture)

gm2-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Modula-2 compiler (based on GCC) for the mips architecture

gnat-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Ada compiler

gobjc++-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Objective-C++ compiler

gobjc++-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Objective-C++ compiler (multilib support)

gobjc++-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Objective-C++ compiler

gobjc++-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Objective-C++ compiler (multilib support)

gobjc++-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Objective-C++ compiler for the mips architecture

gobjc++-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Objective-C++ compiler for the mips architecture

gobjc-10-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Objective-C compiler

gobjc-10-multilib-mips-linux-gnu/focal 10-20200324-1ubuntu1cross1 amd64
  GNU Objective-C compiler (multilib support) (cross compiler for mips architecture)

gobjc-9-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Objective-C compiler

gobjc-9-multilib-mips-linux-gnu/focal 9.3.0-10ubuntu1cross1 amd64
  GNU Objective-C compiler (multilib support) (cross compiler for mips architecture)

gobjc-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Objective-C compiler for the mips architecture

gobjc-multilib-mips-linux-gnu/focal 4:9.2.1-4.1 amd64
  GNU Objective-C compiler for the mips architecture

得知gcc的mips交叉环境编译包,故安装

apt install cpp-mips-linux-gnu g++-mips-linux-gnu

然后检查安装结果

$ mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/mips-linux-gnu/9/lto-wrapper
Target: mips-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu1' --with-bu
gurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,ob
jc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --enable-s
hared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enab
le-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-
gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable
-libquadmath-support --enable-plugin --with-system-zlib --without-target-system-zlib --en
able-libpth-m2 --enable-multiarch --disable-werror --enable-multilib --with-arch-32=mips3
2r2 --with-fp-32=xx --with-lxc1-sxc1=no --enable-targets=all --with-arch-64=mips64r2 --en
able-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mips-linu
x-gnu --program-prefix=mips-linux-gnu- --includedir=/usr/mips-linux-gnu/include
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu1)  
$ mips-linux-gnu-g++ -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/mips-linux-gnu/9/lto-wrapper
Target: mips-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-10ubuntu1' --with-bu
gurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,ob
jc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --enable-s
hared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-
threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enab
le-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-
gnu-unique-object --disable-libitm --disable-libsanitizer --disable-libquadmath --disable
-libquadmath-support --enable-plugin --with-system-zlib --without-target-system-zlib --en
able-libpth-m2 --enable-multiarch --disable-werror --enable-multilib --with-arch-32=mips3
2r2 --with-fp-32=xx --with-lxc1-sxc1=no --enable-targets=all --with-arch-64=mips64r2 --en
able-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=mips-linu
x-gnu --program-prefix=mips-linux-gnu- --includedir=/usr/mips-linux-gnu/include
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu1)  


ZLIB库编译

ZLIB源代码下载地址:

http://www.zlib.net/

下载源代码解压后,执行

./configure --prefix="$HOME/zlib"

然后编辑makefile文件,找出所有的“=gcc”,改为“=mips-linux-gnu-gcc”

CC=gcc

CFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DZLIB_DEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
#           -Wstrict-prototypes -Wmissing-prototypes

SFLAGS=-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
LDFLAGS=
TEST_LDFLAGS=-L. libz.a
LDSHARED=gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
CPP=gcc -E

改成

CC=mips-linux-gnu-gcc

CFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
#CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
#CFLAGS=-g -DZLIB_DEBUG
#CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
#           -Wstrict-prototypes -Wmissing-prototypes

SFLAGS=-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN
LDFLAGS=
TEST_LDFLAGS=-L. libz.a
LDSHARED=mips-linux-gnu-gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map
CPP=mips-linux-gnu-gcc -E

然后执行

make & make install

然后进入用户目录下的zlib目录,这就是编译出来的zlib了

*编译需要zlib的软件,可以使用

./configure --with-zlib=$HOME/zlib

进行指定