$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"
GOARM="5"
AR="ar"
CC="arm-linux-gnueabihf-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 -marm -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build672478070=/tmp/go-build -gno-record-gcc-switches"
My file structure is as follows under $GOPATH/src:
demo
|----demo.go
main
|----main.go
$cat main.go
package main
import demo
func main() {
demo.Demo()
}
I wanted to cross compile the dynamic library for arm on my linux/amd64 computer and execute the cmd as follows:
$export GOARCH=arm
$export CGO_ENABLED=0
$export CC=arm-linux-gnueabihf-gcc
$go install -buildmode=shared -linkshared std
$go install -buildmode=shared -linkshared demo
The last command lead to error:
installing shared library: cannot use packages demo and runtime/cgo from different roots /home/summi/go/pkg/linux_arm_dynlink and /opt/go/pkg/linux_arm_dynlink
I am so confused that I have exported the CGO_ENABLED=0 but cgo still appears in the error. Besides, I have tried several different cross compliers including arm-linux-gcc and arm-linux-gnueabi-gcc, but the error is still the same. What is weird is that these two paths about linux_arm_dynlink even do not exist in my computer.
How can I compile a dynamic library for arm on linux/amd64? Thank you so much for helping me…QAQ