Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cross compile dynamic library for arm on linux/amd64 #39106

Closed
FunnyExplorer opened this issue May 16, 2020 · 1 comment
Closed

cross compile dynamic library for arm on linux/amd64 #39106

FunnyExplorer opened this issue May 16, 2020 · 1 comment

Comments

@FunnyExplorer
Copy link

@FunnyExplorer FunnyExplorer commented May 16, 2020

What version of Go are you using (go version)?

$ go version
go version go1.13.5 linux/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="arm"
GOBIN=""
GOCACHE="/home/summi/.cache/go-build"
GOENV="/home/summi/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/summi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="0"
GOMOD=""
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-build687696122=/tmp/go-build -gno-record-gcc-switches"

I am under amd64 and I want to cross compile a dynamic library for arm. My document structure is as follows:
in GOPATH/src :
/demo
|----demo.go
/main
|----main.go

$ cat main.go
package main
import demo

func main(){
demo.Demo()
}
I have execute the command as follows:
$ export GOARCH="arm"
$ export CGO_ENABLED="0"
$ go install -buildmode=shared -linkshared std
$ go install -buildmode=shared -linkshared demo
$ go build -linkshared main.go

These produce libstd.so in $GOROOT/pkg/linux_amd64_dynlink, libdemo.so in $GOPATH/pkg and a binary file called main in $GOPATH/src.
However, when I put these 3 files on arm, the binary file called main can not be run because of file format error.
How can I cross compile the dynamic library for arm on my linux/amd64 computer???

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented May 16, 2020

You need to have a cross-compiler from linux/amd64 to ARM.

In general we do not use the issue tracker for questions. You will get better and faster answers in a forum. See https://golang.org/wiki/Questions. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.