sadfQED2
V2EX  ›  问与答

golang 在 mipsle 平台的问题

  •  
  •   sadfQED2 · Jun 23, 2020 · 2575 views
    This topic created in 2187 days ago, the information mentioned may be changed or developed.

    本猿互联网后端仔一只,想写点程序放路由器上面运行。经过查询,golang 支持 mipsle,我手持 newifi3 一台,但是我用 win10 go1.14 无论怎么编译,放到路由器上面运行,始终输出 bus error 。 这玩意究竟啥意思,好像根本搜不到这方面的资料,各位老哥谁懂行的?给指点一下?

    golang 代码只有一行,如下

    package main
    
    import (
    	"fmt"
    )
    
    func main() {
    	fmt.Println("hello world!")
    }
    
    
    

    编译命令:

    set GOOS=linux
    
    set GOARCH=mipsle
    
    go build main.go
    
    

    路由器 uname

    Linux OpenWrt 4.14.172 #0 SMP Mon Apr 6 15:29:11 2020 mips GNU/Linux
    
    Supplement 1  ·  Jun 24, 2020
    我自己找到原因了,是因为路由器的 cpu 不支持浮点运算,编译需要加个参数:


    GOMIPS=softfloat GOOS=linux GOARCH='mipsle' go build main.go


    另外:

    GOMIPS=softfloat GOOS=linux GOARCH='mipsle' go build -ldflags "-s -w" main.go

    加上这个参数可以让编译出来的文件小大约 0.5M,路由器上面还是挺宝贵的
    11 replies    2023-06-13 16:26:58 +08:00
    polaa
        1
    polaa  
       Jun 23, 2020
    因为路由器上的系统是阉割版 linux 大概的可能的不满足依赖? 不是很确定

    一般编译嵌入式设备是是使用 buildroot 或者 crosstool-ng 等嵌入式平台的交叉编译工具链
    ysc3839
        2
    ysc3839  
       Jun 24, 2020 via Android
    尝试用 OpenWrt 的 SDK 编译?
    Reficul
        3
    Reficul  
       Jun 24, 2020
    mipsle 有好几个细分的 Target , 比如 mips mips64 mips64le mipsle
    sadfQED2
        4
    sadfQED2  
    OP
       Jun 24, 2020 via Android
    @Reficul 我每个都尝试了,都不管用
    sadfQED2
        5
    sadfQED2  
    OP
       Jun 24, 2020 via Android
    @polaa 好的,我去查查,多谢
    sadfQED2
        6
    sadfQED2  
    OP
       Jun 24, 2020 via Android
    @ysc3839 多谢, 我去查查咋用
    goofool
        7
    goofool  
       Jun 24, 2020
    1 、路由器空间够么
    2 、ldd main 看看
    sadfQED2
        8
    sadfQED2  
    OP
       Jun 24, 2020
    @goofool ldd: main: Not a valid dynamic program
    sadfQED2
        9
    sadfQED2  
    OP
       Jun 24, 2020
    @polaa
    @ysc3839

    https://github.com/kuoruan/openwrt-frp/blob/master/Makefile

    https://github.com/kuoruan/openwrt-v2ray/blob/master/Makefile

    请问老哥说的是这种吗,我看了别人项目的编译,为啥是一个 Makefile 呀,我理解的 go 语言编译不应该是 go build 一下就行了么,Makefile 不应该是 c 语言里面的么,这样的话我那个 hello word 要咋写 Makefile 呢,能给个关键词么,搜了半天都没搜到相关资料
    ysc3839
        10
    ysc3839  
       Jun 24, 2020
    @sadfQED2 因为这是配合 OpenWrt 的 build system 用的,而这套 build system 是基于 make 的,所以要求写 Makefile 。
    cosmain
        11
    cosmain  
       Jun 13, 2023
    这个 CPU 没有 FPU ,要软浮点。
    GOMIPS=softfloat
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1577 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 16:21 · PVG 00:21 · LAX 09:21 · JFK 12:21
    ♥ Do have faith in what you're doing.