首页 > 解决方案 > 使用 tinygo 从 x64 Linux 编译 arm 二进制文件:未定义的参考问题

问题描述

当我输入以下命令时,我正在尝试使用 Linux 中的 tinygo 编译程序:

GOARCH=arm tinygo build -o <OutputName> ./main.go

我有 :

/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /tmp/tinygo859602615/main.o: in function `syscall.Seek':
/usr/local/go/src/syscall/syscall_linux_arm.go:60: undefined reference to `syscall.seek'

上面显示的相关代码是:

// Underlying system call writes to newoffset via pointer.
// Implemented in assembly to avoid allocation.
func seek(fd int, offset int64, whence int) (newoffset int64, err Errno)

func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
    newoffset, errno := seek(fd, offset, whence)
    if errno != 0 {
        return 0, errno
    }
    return newoffset, nil
}

我刚刚使用sudo apt-get install arm-linux-gnueabihf来安装这个包。

但是,GOARCH=arm go build -o ./main.go可以正常工作。使用 CGO_ENABLED="0" 标志不会改变任何东西。我在网上搜索过,没有发现类似的问题。感谢您提供任何可能的信息。

环境 :

Linux 5.4.0-73-generic #82-Ubuntu SMP Wed Apr 14 17:39:42 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
go version go1.16.3 linux/amd64
CGO_ENABLED="1"
GOROOT="/usr/local/go"
TINYGOROOT="/usr/local/lib/tinygo"

标签: linuxgoarmcross-compilingtinygo

解决方案


推荐阅读