Cross compiling sers (with CGO) to Android

395 views
Skip to first unread message

distributed

unread,
Aug 28, 2018, 12:06:05 PM8/28/18
to golang-nuts
I am trying to cross compile the sers library from github.com/distributed/sers to arm64 android.

I have an Android SDK on my computer and I point $AR, $CC, $CXX and so on to the relevant programs.

In a checkout of the sers library (git clone https://github.com/distributed/sers.git) I run:

~/tmp/sers$ CGO_ENABLED=1 GOARCH=arm64 GOOS=linux go get
# runtime/cgo
/home/joe/android/toolchain/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: cannot find -lpthread
clang60
: error: linker command failed with exit code 1 (use -v to see invocation)

My go env is:

~/tmp/sers$ CGO_ENABLED=1 GOARCH=arm64 GOOS=linux go env
GOARCH
="arm64"
GOBIN
=""
GOCACHE
="/home/joe/.cache/go-build"
GOEXE
=""
GOFLAGS
=""
GOHOSTARCH
="amd64"
GOHOSTOS
="linux"
GOOS
="linux"
GOPATH
="/home/joe/gop"
GOPROXY
=""
GORACE
=""
GOROOT
="/usr/local/go"
GOTMPDIR
=""
GOTOOLDIR
="/usr/local/go/pkg/tool/linux_amd64"
GCCGO
="gccgo"
CC
="aarch64-linux-android-clang"
CXX
="aarch64-linux-android-clang++"
CGO_ENABLED
="1"
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 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build095666131=/tmp/go-build -gno-record-gcc-switches"

I am using Go 1.11.


I suspect that the toolchain attempts to link against -lpthread, but this is not necessary, since pthread functionality is included in the C library in Android.

Does anybody know how to circumvent this build problem?

distributed

unread,
Aug 30, 2018, 7:25:36 AM8/30/18
to golang-nuts
This is embarassing, but setting GOOS=android fixed the issue.

I was under the impression that android builds were only supported with an addition to the toolchain.
Reply all
Reply to author
Forward
0 new messages