请随时查看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
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