Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C for Mips architecture

I have seen several ways to do this (and so far I havent tried a couple but I want to isolate this one for ease)

There is supposed to be a way to do this VIA gcc and I would prefer this i just keep hitting walls.

I am using debian7 and can use what ever other flavor out there (I am for the time being wanting to avoid qemu casue I want something smaller scale.) I am following this example found here.

http://moozing.wordpress.com/2011/04/05/cross-compile-in-debian/

I have been able to do everything and during part of this I had to install libgmp3c2-dummy_1.0_all.deb for ti to continue

just now I need to compile and all I am compiling is a simple hello world script however , upon compiling I can't cause libgmp.so.3 is not in the /usr/lib/ dir however, there is one in /usr/lib/mips-linux-gnu-gcc folder I thought I'd copy it over to see if get it to compile and I get that this elf file is encoded in big-endian which makes sense. but what is it that I am missing to compile this file??

and I tried to compile the thing as big endian I think that either that I have confusion from the libraries or that I need a differnt libgmp.so.3 ..

also I tried apt-get install libgmp-dev libgmp3-dev too.

Thank you for helping helping if you can! :) and if you know of a simple way to do this that wont take a bunch of space on the my machine then I am open but I would like to try with GCC and using the tool chain.

Thanks!

like image 822
LUser Avatar asked Jun 09 '13 05:06

LUser


2 Answers

Well I managed to compile MIPS in Debian. Edit I want to improve this answer for ease for use to others...

    1. deb http://www.emdebian.org/debian stable main to /etc/apt/sources.list 

    2. apt-get update.

    3. install libgmp3c2 from https://packages.debian.org/squeeze/libgmp3c2

    4. apt-get install gcc-4.3-mips-linux-gnu libgmp3c2-mips-cross this worked

then just mips-linux-gnu-gcc file.c -o executable

That's it.

PS if you're working on Routers.... use the -static option when compiling. So in the end it looked like

mips-linux-gnu-gcc -EB -march=34kc -static test.c -o test

If you have problems with a keyring public key not being recognized, use the emdebian-archive-keyring package which can be installed using apt.

like image 149
LUser Avatar answered Sep 29 '22 14:09

LUser


Why not just install the free Mentor/Codesourcery gcc MIPS cross compiler, instead of trying to build one from scratch?

When you have a MIPS cross compiler installed, you should install MIPS libraries in the appropriate directory for the cross compiler, and not in the /usr/lib directory for your host linux installation. You cannot use apt-get to attempt to install MIPS libraries, since that tool can only install libraries for your host linux installation.

like image 45
markgz Avatar answered Sep 29 '22 14:09

markgz