gobind (x/mobile) not working after Go was cross compiled

557 views
Skip to first unread message

Philippe Quesnel

unread,
Mar 1, 2015, 10:00:48 AM3/1/15
to golan...@googlegroups.com
Hi,

I get an error when running gobind on a simple go file after I cross compiled the Go tools for android...

Just tried with Go devel +cb37cfa Sun Mar 1 10:08:49 2015 +0000

What I do:

# update go dev & build go
cd ~/godev
git pull 
cd src
export GOROOT_BOOTSTRAP=~/go1.4.2/
./make.bash

# update x/mobile

# install gobind

# run gobind (separate shell by the way)
# PS: GOPATH=/home/philippe/code/mppq:/home/philippe/code/go

.. it works fine.

Now:
# build Go cross compiler for android
# NDK is android-ndk-r10d
CC_FOR_TARGET=$NDK_ROOT/bin/arm-linux-androideabi-gcc GOOS=android GOARCH=arm GOARM=7 ./make.bash

note that I get this warning a few times?:
warning: unable to find runtime/cgo.a

# run gobind (same separate shell as last run of gobind)

and now I get this:
arm-linux-androideabi-gcc: error: unrecognized command line option '-m64'
cgo failed: [go tool cgo -objdir /tmp/net_C843240927 -- -I /tmp/net_C843240927 cgo_linux.go cgo_unix.go]: exit status 1
/home/philippe/godev/src/net/lookup_unix.go:56:20: undeclared name: cgoLookupHost
/home/philippe/godev/src/net/lookup_unix.go:64:20: undeclared name: cgoLookupIP
/home/philippe/godev/src/net/lookup_unix.go:72:19: undeclared name: cgoLookupPort
/home/philippe/godev/src/net/lookup_unix.go:80:20: undeclared name: cgoLookupCNAME
couldn't load packages due to errors: net

It looks to me like the Go toolchain is confused/mixed-up, using the arm cross-compiler stuff instead of the native linux/amd64 !???
Or is it something about with the way gobind works ?

I guess I could always use a third separate Go installation for the android cross compile,
but having 3 Go installations is not my favorite way of doing things ;-p

Any suggestions, am I doing something wrong or is there an actual problem?

Thank you

Daniel Skinner

unread,
Mar 1, 2015, 10:15:05 PM3/1/15
to Philippe Quesnel, golang-nuts
When cross-compiling, you'll want to do something like this

cd $GOROOT/src 
./make.bash 
CC_FOR_TARGET=$NDK_ARM_CC GOOS=android GOARCH=arm GOARM=7 ./make.bash --no-clean
./make.bash --no-clean

The last make.bash "fixes" things up. There's details in other threads covering the details of this.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Philippe Quesnel

unread,
Mar 2, 2015, 12:04:09 PM3/2/15
to golan...@googlegroups.com, philippe...@gmail.com
ah! ok, thank you very much, I will try this.

Philippe Quesnel

unread,
Mar 2, 2015, 9:06:59 PM3/2/15
to golan...@googlegroups.com, philippe...@gmail.com
hmmm, it does work ... but then I can't cross compile (a go program/lib) for android,
I just get a different error !
(something like 'gcc unknown command line option '-marm', forgot to take note of the error and I don't have the branch anymore hehe)

Seems like I can't have both linux/amd64 AND android/arm under the same go tree/build !!!???
I'll just use two copies for now.

thx

David Crawshaw

unread,
Mar 3, 2015, 11:16:25 AM3/3/15
to Philippe Quesnel, golang-nuts
Multiple cgo-enabled compilers interact badly, which is one of the
reasons we are working on the gomobile tool to help manage them. It
will have a bind subcommand to make this process a little less
messier.

It is not quite ready yet, when it is we will update the x/mobile documentation.

Daniel Skinner

unread,
Mar 3, 2015, 11:31:29 AM3/3/15
to Philippe Quesnel, golang-nuts
Yeah, I should have added you'll need additional ENV variables set when doing the cross compile. I wrote a short utility to assist with how I do this at https://github.com/dskinner/mobilize

Note, the above tool is just something for the interim I was using until the mobile repo comes along more.

I forget the exact details as its been a couple months but you can look at this func specifically: https://github.com/dskinner/mobilize/blob/master/mobilize.go#L151

Philippe Quesnel

unread,
Mar 3, 2015, 11:39:58 AM3/3/15
to golan...@googlegroups.com, philippe...@gmail.com
thank you everybody.

Actually with the current dev Go version (yesterday evening), I cannot even get a properly working android cross compile to work !
It compiles fine but the app crashes, complaining about some missing go/c module .. 
it probably is related to the warnings I mentioned, that I get when building the Go compiler for android :
warning: unable to find runtime/cgo.a

I think I'll let the dust settle a bit for now and try this again later ;-)
thx again
Reply all
Reply to author
Forward
0 new messages