Cross compile errors for ARM64

I am trying to compile for arm64 while my host arch is amd64.

GOARCH=“arm64”
GOBIN=""
GOEXE=""
GOHOSTARCH=“amd64”
GOHOSTOS=“linux”
GOOS=“linux”
GOPATH="/home/works"
GORACE=""
GOROOT="/home/go"
GOTOOLDIR="/home/go/pkg/tool/linux_amd64"
GCCGO=“gccgo”
CC=“gcc”
GOGCCFLAGS="-fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build513447869=/tmp/go-build -gno-record-gcc-switches"
CXX=“arm-linux-gnueabi-g++”
CGO_ENABLED=“1”
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG=“pkg-config”
abc@Ubuntu:~/works$ echo $CC_FOR_TARGET
arm-linux-gnueabi-gcc

build command:
go install -ldflags “-w -X main.commitVer=f7f6857 -X main.version=2.10.0”

Errors:
/home/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/usr/bin/ld: /tmp/go-link-232946962/go.o: Relocations in generic ELF (EM: 183)
/tmp/go-link-232946962/go.o: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

I think the problem is using a wrong linker /home/go/pkg/tool/linux_amd64/link. How can I change to the right linker.

Disclaimer: I haven’t reviewed how go install works before asking here, but how do you go install across architectures? Does it work if you just go build?

doesn’t matter

go build -ldflags “-w -X main.commitVer=f7f6857 -X main.version=2.10.0”

produces the same linker error.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.