Compile C for Mips architecture

2019-03-30 18:20发布

问题:

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!

回答1:

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.



回答2:

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.



回答3:

You can reference this post Setting up cross-compiler for MIPS-I version 1 since it seems to be the simplest solution to your problem since you want to simply cross-compile for MIPS (reference his answer to the question as well). Note I haven't actually tested it.

I have built GCC to show the source in MIPS assembly from my ARM processor, but I can't seem to find the guide anymore. But you may want to look into building gcc for cross-compiling as well. I'll update this post in a few days since this has intrigued me to write a simple HOWTO set up a MIPS cross-compiler.