简体   繁体   English

golang 二进制文件不在 mips 上运行

[英]golang binary not running on mips

I'm using Go 1.11.4 on Windows 10 and I want to compile code for a MIPS 74Kc processor (Qualcomm Atheros QCA9558) running Linux.我在 Windows 10 上使用 Go 1.11.4,我想为运行 Linux 的 MIPS 74Kc 处理器(Qualcomm Atheros QCA9558)编译代码。 I compile with:我编译:

GOOS=linux GOARCH=mips go build

Get an executable, upload and run it and get:获取可执行文件,上传并运行它并获得:

Illegal instruction

Try again w/ GOARCH=mipsle and get:GOARCH=mipsle再试一次,得到:

./hello_mipsle_linux: line 1: syntax error: unexpected "("

What am I missing?我错过了什么?

My host doing the build had an FPU but the board does not.我的主机进行构建时有一个 FPU,但电路板没有。 Adding GOMIPS=softfloat fixed it:添加GOMIPS=softfloat修复它:

GOOS=linux GOARCH=mips GOMIPS=softfloat go build

To list all possible MIPS architects available to your current build toolchain, use the go tool eg要列出当前构建工具链可用的所有可能的 MIPS 架构师,请使用go tool例如

$ go version

go version go1.12 darwin/amd64

$ go tool dist list | grep mips

linux/mips
linux/mips64
linux/mips64le
linux/mipsle

so probably one of the remaining GOARCH permutations you have not tried eg mips64 or mips64le .所以可能是您还没有尝试过的其余GOARCH排列之一,例如mips64mips64le

uname -m would help to determine your target system's machine architecture. uname -m将有助于确定您的目标系统的机器架构。

I have a similar issue and it's solved by setting GOARCH=mipsle .我有一个类似的问题,它已通过设置GOARCH=mipsle解决。 This should work这应该工作

GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build

My core is MIPS 24KEc V5.0 , see my blog https://zyfdegh.github.io/post/202002-go-compile-for-mips/我的核心是MIPS 24KEc V5.0 ,看我的博客https://zyfdegh.github.io/post/202002-go-compile-for-mips/

If it's not OK, try these steps如果不行,请尝试以下步骤

  1. Check the CPU architecture, Big-Endian or Little-Endian, by检查 CPU 架构,Big-Endian 或 Little-Endian,通过
$ lscpu | grep "Byte Order"

cat /proc/cpuinfo would also be helpful. cat /proc/cpuinfo也会有帮助。

  1. Check kernel info, mips or mips64, for me it's mips (32)检查内核信息,mips 或 mips64,对我来说是 mips (32)
$ uname -a
Linux OpenWrt 4.14.151 #0 Tue Nov 5 14:12:18 2019 mips GNU/Linux
  1. If it's Little-Endian, set GOARCH=mipsle , if it's 64bit Little-Endian, set set GOARCH=mips64le如果是 Little-Endian,设置GOARCH=mipsle ,如果是 64bit Little-Endian,设置 set GOARCH=mips64le

Another related question Writing and Compiling Program For OpenWrt hope it helps.另一个相关问题为 OpenWrt 编写和编译程序希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM