Document Actions

School of Engineering Computing Support - MIPS Cross-compiler

How to create a MIPS cross-compiler package for Ubuntu


To support certain computer science and engineering classes, the School of Engineering has developed a MIPS cross-compiling package. It is designed to be run on i386 architecture systems and to produce object code and programs for big-endian 32-bit MIPS systems.


The package exists as a tarball, and functions properly. Once the archive has been extracted and the user's PATH modified, the usual cross-compiling programs can be executed by prepending "mips-". For example:

$ mips-gcc -o hello hello.c

would produce a program "hello" which should run on a MIPS-based Linux system.

The latest package can be downloaded here: ccmips-20070927.tar.gz




The program used to create the cross-compiler is crosstool. The steps followed were:


  • Download crosstool
  • Make minor modifications
  • Execute crosstool
  • Create symbolic links in the cross-compiling bin directory
  • Create the archive and make it available for download


Using crosstool


Basically, follow its howto

with a few modifications. It might be useful to download a more recent version (if one is available), but 0.43 is known to work. Perform the following commands:

$ wget
$ tar xzvf crosstool-0.43.tar.gz
$ cd crosstool-0.43


Now edit You are changing all of the lines in the first section (between the first and second blocks of comments). The variables changed are RESULT_TOP, GCC_LANGUAGES, and PARALLELMFLAGS. Adjust PARALLELMFLAGS to reflect the number of CPUs on the build system.

set -ex

[!?  In spring 2010, CL didn't *find* some of these lines in 0.43 but *did* need to edit .../crosstool-0.43/build/mips-unknown-linux-gnu/gcc-3.4.5-glibc-2.3.6/build-glibc/csu/version-info.h by combining lines 2 and 3].

'bison' and 'flex' are pre-requisites.

glibc 2.3.6 seems to need an additional patch. Place the following file in patches/glibc-2.3.6:


Now you are ready to build. This will take a while.

Note: if you're rebuilding, you might want to remove the directory ~/crosstool/ccmips first.

$ sh

The final command will download sources, compile them, and install them to $HOME/crosstool.


Prepare for packaging

The directory is unwieldy and so are the executable names. Symbolic links help. Also, there is a hard link which might not be amenable to the sshfs filesystem that we use, so change that into a symbolic link as well.

cd ~/crosstool
mv gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu ccmips
cd ccmips/bin
for foo in addr2line ar as c++filt cpp gcc-3.4.5 gcc gccbug gcov gprof ld nm \
objcopy objdump ranlib readelf size strings strip; \
do ln -s mips-unknown-linux-gnu-$foo mips-$foo; done
rm mips-unknown-linux-gnu-gcc
ln -s mips-unknown-linux-gnu-gcc-3.4.5 mips-unknown-linux-gnu-gcc


Create the package

cd ~/crosstool
tar -c ccmips | gzip > ~/ccmips-YYYYMMDD.tar.gz

Note: replace YYYYMMDD in the final filename with the current date. Append _X (underscore, index number) if this is not the first one created on this date.

Then place the tarball where it can be downloaded.



Individual use


To install the cross-compiler to an individual user account, do the following.

$ wget
$ tar xzvf ccmips-20070927.tar.gz

Next edit ~/.bash_login so that it contains:

. .bashrc

Then edit ~/.bashrc so that it contains:

export PATH=$PATH:~/ccmips/bin

Systemwide installation

To install the cross-compiler so that all users can use it, do the following as root.

cd /opt
tar xzvf ccmips-20070927.tar.gz
rm ccmips-20070927.tar.gz

Next make sure that everyone's path contains /opt/ccmips/bin.


Set your path if you've only just modified ~/.bashrc, by entering the following at the prompt:

$ export PATH=$PATH:~/ccmips/bin

Make sure you have sample source code, such as hello.c like the following:

#include <stdio.h>

int main(int argc, char **argv)
   printf("Hello, world!\n");
   return 0;

Compile and link:

$ mips-gcc -o hello hello.c

Verify the output file is for MIPS:

$ file hello
hello: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), for GNU/Linux 2.4.18, dynamically linked (uses shared libs), not stripped




xgcc toolchain

An alternative toolchain, favored by those coming from Berkeley, appears here.