【问题标题】:golang binary not running on mipsgolang 二进制文件未在 mips 上运行
【发布时间】:2020-02-16 03:19:11
【问题描述】:

我在 Windows 10 上使用 Go 1.11.4,我想为运行 Linux 的 MIPS 74Kc 处理器 (Qualcomm Atheros QCA9558) 编译代码。我编译:

GOOS=linux GOARCH=mips go build

获取一个可执行文件,上传并运行它并获取:

Illegal instruction

使用GOARCH=mipsle 重试并获取:

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

我错过了什么?

【问题讨论】:

  • 我们能解决这个问题吗?我也有类似的问题
  • 是的。请看下面我的回答。只需添加GOMIPS=softfloat

标签: go mips


【解决方案1】:

我做构建的主机有一个 FPU,但板子没有。添加GOMIPS=softfloat 修复它:

GOOS=linux GOARCH=mips GOMIPS=softfloat go build

【讨论】:

  • 仅供参考:这些 MIPS 二进制文件也可以在 Unifi AC 接入点上运行! :D
【解决方案2】:

要列出当前构建工具链可用的所有可能的 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

所以可能是您尚未尝试过的其余 GOARCH 排列之一,例如mips64mips64le

uname -m 有助于确定目标系统的机器架构。

【讨论】:

    【解决方案3】:

    我有一个类似的问题,通过设置GOARCH=mipsle 解决了。这应该工作

    GOOS=linux GOARCH=mipsle GOMIPS=softfloat go build
    
    

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

    如果不行,试试这些步骤

    1. 检查 CPU 架构,Big-Endian 或 Little-Endian,作者:
    $ lscpu | grep "Byte Order"
    

    cat /proc/cpuinfo 也会有所帮助。

    1. 检查内核信息、mips 或 mips64,对我来说是 mips (32)
    $ uname -a
    Linux OpenWrt 4.14.151 #0 Tue Nov 5 14:12:18 2019 mips GNU/Linux
    
    1. 如果是Little-Endian,设置GOARCH=mipsle,如果是64bit Little-Endian,设置GOARCH=mips64le

    另一个相关问题Writing and Compiling Program For OpenWrt希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多