请随时查看dockcross 项目。他们为各种架构提供了作为 docker 容器的跨工具链。
就个人而言,我更喜欢让我的主机系统尽可能干净,所以这对我来说是完美的匹配。
要启动并运行一个简单的 hello world 示例,请按照README.rst 中的步骤操作。
MIPS 上的 HelloWorld.c
但是,请查看我的 hello world 编译以了解运行 DD-WRT 的 Netgear N600 wndr3700v2 路由器。 (我已经链接了 openWRT wiki 页面而不是 dd-wrt,更喜欢这个)。
检查路由器上使用了哪个架构,请信任 wiki 页面或通过 ssh/telnet 连接并运行 uname -a 命令。
root@DD-WRT:~# uname -a
Linux DD-WRT 3.10.108-d10 #63184 Tue Nov 3 05:20:50 +03 2020 mips DD-WRT
所以我们可以从 dockerhub 拉取 mips 容器:
# 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
让我们创建一个名为helloWorld 的简单项目文件夹,并在其中添加一些代码。
# helloWorld.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
printf("Hello World from dockercrossMips\n");
return EXIT_SUCCESS;
}
现在我们可以用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
...
现在我们已准备好传输并运行您的 helloWorld 可执行文件。
# copy via scp, use your favorite method
user@x86-host:~# scp helloWorld root@192.168.0.2:/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
如果您不知道您的装载机在哪里,请使用file 命令。如果命令不可用,请查看entware 项目。
这里是官方的 dd-wrt install tut here