每当我尝试使用' go install'设置goarch,goos和gobin之后我得到了GOBIN设置时无法安装交叉编译的二进制文件,但是不明白为什么?
为arm linux构建最简单的方法是什么?
答案 0 :(得分:5)
您可以改用go build命令:
env GOOS=android GOARCH=arm64 go build -o /arm64bins/app
Go 1.7中的可用GOOS/GOARCH
:
➜ go tool dist list | grep arm 05/29/16
android/arm
android/arm64
darwin/arm
darwin/arm64
freebsd/arm
linux/arm
linux/arm64
nacl/arm
netbsd/arm
openbsd/arm
plan9/arm
答案 1 :(得分:2)
这对我有用(从win64到linux arm6的交叉编译):
我首先在终端设置这些:
set GOARCH=arm
set GOBIN=D:\work\go\bin
set GOEXE=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=linux
set GOPATH=D:\work\go
set GORACE=
set GOROOT=c:\go
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-fPIC -marm -fmessage-length=0
set CXX=g++
set CGO_ENABLED=0
然后简单地说:
去建造
它为目标生成二进制输出(ok)
然后将二进制输出复制到目标系统并运行
我认为你应该使用“go build”而不是“go install”进行交叉编译。
答案 2 :(得分:0)
env GOOS=android GOARCH=arm64 go build test.go
返回错误
# command-line-arguments
/usr/lib/go-1.10/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/x86_64-linux-gnu-ld: /tmp/go-link-711744324/go.o: Relocations in generic ELF (EM: 183)
/tmp/go-link-711744324/go.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status