please feel free to look into dockcross project. They offer cross tool-chains as docker containers for various architectures.
Personally, I prefer to keep my host system as clean as possible, so this is a perfect match for me.
To get a simple hello world example up and running please just follow the steps from the README.rst.
HelloWorld.c on MIPS
However, please checkout my hello world compilation for a Netgear N600 wndr3700v2 router running DD-WRT. (I have linked the openWRT wiki page instead of the dd-wrt, prefer this one).
Check which arch is used on the router, please trust the wiki pages or just connect via ssh/telnet and run uname -a command.
root@DD-WRT:~# uname -a
Linux DD-WRT 3.10.108-d10 #63184 Tue Nov 3 05:20:50 +03 2020 mips DD-WRT
So we can pull the mips container from dockerhub:
# pull dockcross container for mips
# repo: dockerhub -> https://hub.docker.com/r/dockcross/linux-mips
user@x86-host:~# docker pull dockcross/linux-mips:latest
# check if everything went correct
user@x86-host:~# docker images
dockcross/linux-mips latest cf6e2d5003c8 3 years ago 1.03GB
# create dockcross runner
user@x86-host:~# docker run --rm dockcross/linux-mips > ./dockercross-mips
user@x86-host:~# chmod +x ./dockercross-mips
# this will create a dockercross runner script in the current directory
Let's create a simple project folder called helloWorld
and but some code into it.
# helloWorld.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("Hello World from dockercrossMips\n");
return EXIT_SUCCESS;
}
Now we can compile it with dockcross
.
# check if all files exists
user@x86-host:~# ll
total 12K
-rwxr-xr-x 1 user user 5.5K Feb 12 19:22 dockercross-mips
-rw-r--r-- 1 user user 151 Feb 12 18:51 helloWorld.c
# compile source into ELF
user@x86-host:~# ./dockercross-mips bash -c '$CC ./helloWorld.c -o helloWorld'
# check ELF file -> should show the proper type and machine
user@x86-host:~# readelf -h helloWorld
ELF Header:
Magic: 7f 45 4c 46 01 02 01 00 01 00 00 00 00 00 00 00
Class: ELF32
...
OS/ABI: UNIX - System V
ABI Version: 1
Type: EXEC (Executable file)
Machine: MIPS R3000
...
Now we are ready to transfer and run your helloWorld
executable.
# copy via scp, use your favorite method
user@x86-host:~# scp helloWorld [email protected]:/tmp/root/
# run it
root@DD-WRT:~# ./helloWorld
# if you get some error like this one: -sh: ./helloWorld: not found
# please just start it via your loader
root@DD-WRT:~# /lib/ld-musl-mips-sf.so.1 helloWorld
# and you should see the desire output.
Hello World from dockercrossMips
In case you do not know where your loader is located, please use file command. In case the command is not available, please checkout entware project.
Here would be the official dd-wrt install tut here