Closed imwaddy closed 6 years ago
Hi @imwaddy This library is a go wrapper around the official zstd library which is written in C so we use cgo. To compile cgo code, you will need a C toolchain too to cross-compile. I'm not super familiar with cgo cross-compilation but looking at a previous stackoverflow answer, it seems your best bet is to either compile on the target machine or use xgo
HI @Viq111 ,
I'm working on go project that implmenting C code ! I can build the project on linux/amd64, and we now that go don't cross compile if we use "IMPORT C". So i work with XGO that maybe help me to cross compiling for ARM. i check XGO by cross compiling version of my go project without C code and it's work like cross compil of go. my environement :
go version go1.13.3 linux/amd64 Go env :
GO111MODULE="on"
GOARCH="amd64"
GOBIN="/opt/go/bin"
GOCACHE="/home/jj/.cache/go-build"
GOENV="/home/jj/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/opt/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/opt/go/src/github.com/brocaar/lora-app-server/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
My project is on =>
/opt/go/src/github.com/brocaar
My package that include c code is on =>
/opt/go/src/github.com/lorawan
the go.mode of my project :
module github.com/brocaar/lora-app-server
go 1.12
replace github.com/brocaar/lorawan => /opt/go/src/github.com/brocaar/lorawan
require (
cloud.google.com/go v0.44.3
github.com/Azure/azure-service-bus-go v0.9.1
github.com/NickBall/go-aes-key-wrap v0.0.0-20170929221519-1c3aa3e4dfc5
github.com/aws/aws-sdk-go v1.19.19
github.com/brocaar/loraserver v0.0.0-20190917115647-c4da45f52f2b
github.com/brocaar/lorawan v0.0.0-20190814113539-8eb2a8d6da09
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/elazarl/go-bindata-assetfs v1.0.0
github.com/gofrs/uuid v3.2.0+incompatible
github.com/golang/protobuf v1.3.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/goreleaser/goreleaser v0.106.0
)
My command to cross-compil is:
xgo -go 1.13.3 --targets=linux/arm-7 /opt/go/src/github.com/brocaar/lora-app-server/cmd/lora-app-server
The result error are :
src/github.com/brocaar/lora-app-server/cmd/lora-app-server
Checking docker installation... Client: Version: 18.09.7 API version: 1.39 Go version: go1.10.4 Git
commit: 2d0083d Built: Fri Aug 16 14:19:38 2019 OS/Arch: linux/amd64 Experimental: false
Server:
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 2d0083d
Built: Thu Aug 15 15:12:41 2019
OS/Arch: linux/amd64
Experimental: false
Checking for required docker image karalabe/xgo-1.13.3... found.
Cross compiling github.com/brocaar/lora-app-server/cmd/lora-app-server...
Building locally github.com/brocaar/lora-app-server/cmd/lora-app-server...
Bootstrapping linux/arm-7...
go: github.com/brocaar/lorawan@v0.0.0-20190814113539-8eb2a8d6da09: parsing
/opt/go/src/github.com/brocaar/lorawan/go.mod: open
/opt/go/src/github.com/brocaar/lorawan/go.mod: no such file or directory
2019/12/03 16:02:37 Failed to cross compile package: exit status 1.
I really don't now why he say "no such file or directory", because there are go.mod in folder lorawan ! can some one help me ? thanks
I am running into the same issue with xgo.
cd /go/pkg/mod/github.com/!data!dog/zstd@v1.4.5
TERM='dumb' aarch64-linux-gnu-gcc-6 -I . -fPIC -pthread -fmessage-length=0 -fdebug-prefix-map=$WORK/b215=/tmp/go-build -gno-record-gcc-switches -o $WORK/b215/_cgo_.o $WORK/b215/_cgo_main.o $WORK/b215/_x001.o $WORK/b215/_x002.o $WORK/b215/_x003.o $WORK/b215/_x004.o $WORK/b215/_x005.o $WORK/b215/_x006.o $WORK/b215/_x007.o $WORK/b215/_x008.o $WORK/b215/_x009.o $WORK/b215/_x010.o $WORK/b215/_x011.o $WORK/b215/_x012.o $WORK/b215/_x013.o $WORK/b215/_x014.o $WORK/b215/_x015.o $WORK/b215/_x016.o $WORK/b215/_x017.o $WORK/b215/_x018.o $WORK/b215/_x019.o $WORK/b215/_x020.o $WORK/b215/_x021.o $WORK/b215/_x022.o $WORK/b215/_x023.o $WORK/b215/_x024.o $WORK/b215/_x025.o $WORK/b215/_x026.o $WORK/b215/_x027.o $WORK/b215/_x028.o $WORK/b215/_x029.o $WORK/b215/_x030.o $WORK/b215/_x031.o $WORK/b215/_x032.o $WORK/b215/_x033.o $WORK/b215/_x034.o $WORK/b215/_x035.o $WORK/b215/_x036.o $WORK/b215/_x037.o $WORK/b215/_x038.o $WORK/b215/_x039.o $WORK/b215/_x040.o $WORK/b215/_x041.o $WORK/b215/_x042.o -g -O2
TERM='dumb' /usr/local/go/pkg/tool/linux_amd64/cgo -dynpackage zstd -dynimport $WORK/b215/_cgo_.o -dynout $WORK/b215/_cgo_import.go
cat >$WORK/b215/importcfg << 'EOF' # internal
# import config
packagefile bytes=/usr/local/go/pkg/linux_arm64/bytes.a
packagefile errors=/usr/local/go/pkg/linux_arm64/errors.a
packagefile fmt=/usr/local/go/pkg/linux_arm64/fmt.a
packagefile io=/usr/local/go/pkg/linux_arm64/io.a
packagefile io/ioutil=/usr/local/go/pkg/linux_arm64/io/ioutil.a
packagefile runtime=/usr/local/go/pkg/linux_arm64/runtime.a
packagefile sync=/usr/local/go/pkg/linux_arm64/sync.a
packagefile runtime/cgo=/usr/local/go/pkg/linux_arm64/runtime/cgo.a
packagefile syscall=/usr/local/go/pkg/linux_arm64/syscall.a
EOF
/usr/local/go/pkg/tool/linux_amd64/compile -o $WORK/b215/_pkg_.a -trimpath "$WORK/b215=>" -p github.com/DataDog/zstd -buildid TfPd5DiQSn_tf0Dcu5Tx/TfPd5DiQSn_tf0Dcu5Tx -goversion go1.15.8 -D "" -importcfg $WORK/b215/importcfg -pack -c=4 $WORK/b215/_cgo_gotypes.go $WORK/b215/errors.cgo1.go $WORK/b215/zstd.cgo1.go $WORK/b215/zstd_stream.cgo1.go $WORK/b215/_cgo_import.go
/usr/local/go/pkg/tool/linux_amd64/pack r $WORK/b215/_pkg_.a $WORK/b215/_x001.o $WORK/b215/_x002.o $WORK/b215/_x003.o $WORK/b215/_x004.o $WORK/b215/_x005.o $WORK/b215/_x006.o $WORK/b215/_x007.o $WORK/b215/_x008.o $WORK/b215/_x009.o $WORK/b215/_x010.o $WORK/b215/_x011.o $WORK/b215/_x012.o $WORK/b215/_x013.o $WORK/b215/_x014.o $WORK/b215/_x015.o $WORK/b215/_x016.o $WORK/b215/_x017.o $WORK/b215/_x018.o $WORK/b215/_x019.o $WORK/b215/_x020.o $WORK/b215/_x021.o $WORK/b215/_x022.o $WORK/b215/_x023.o $WORK/b215/_x024.o $WORK/b215/_x025.o $WORK/b215/_x026.o $WORK/b215/_x027.o $WORK/b215/_x028.o $WORK/b215/_x029.o $WORK/b215/_x030.o $WORK/b215/_x031.o $WORK/b215/_x032.o $WORK/b215/_x033.o $WORK/b215/_x034.o $WORK/b215/_x035.o $WORK/b215/_x036.o $WORK/b215/_x037.o $WORK/b215/_x038.o $WORK/b215/_x039.o $WORK/b215/_x040.o $WORK/b215/_x041.o $WORK/b215/_x042.o # internal
/usr/local/go/pkg/tool/linux_amd64/buildid -w $WORK/b215/_pkg_.a # internal
cp $WORK/b215/_pkg_.a /root/.cache/go-build/9e/9e746cef3e612bfda6a5e6feaffa31c04bda54ebe52a0526c2f07a697468b5c7-d # internal
2021/03/02 21:52:49 Failed to cross compile package: exit status 2.
When I try to build from this project locally, I get:
$ GOARCH=arm64 go build
go build _/home/someuser/zstd: build constraints exclude all Go files in /home/someuser/zstd
go version
go version go1.10.4 linux/amd64go env
GOARCH="amd64" GOBIN="/home/mayurw/go/bin" GOCACHE="/home/mayurw/.cache/go-build" GOEXE="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/mayurw/go" GORACE="" GOROOT="/usr/lib/go-1.10" GOTMPDIR="" GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="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" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build555451646=/tmp/go-build -gno-record-gcc-switches"I executed the command env GOOS=linux GOARCH=arm64 go build it produced output as bolow go build github.com/DataDog/zstd: build constraints exclude all Go files in ~/go/src/github.com/DataDog/zstd
I'm really not getting what error it is. Please provide solution to go cross compilation from linux to ARM architecture binaries..