To the real interested, I provide a way to cross packages for ARM with cgo support
at the end of the mail (although it doesn't support Android, because we don't support
its bionic libc yet).
setting up correct cross compiler for ARM includes geting these right.
It's certainly possible to do cross compiling with cgo support, but this process
is somewhat complicated.
1. you have to set up a correct cross compiler with basic libc header/library
(note again that currently, we only support glibc)
you should be able to compile some pthread code, for example,
test/bench/shootout/threadring.c in the Go tree. Assume your cross compiler
is named gcc-arm, and is in $PATH, try:
gcc-arm test/bench/shootout/threadring.c;
then copy the a.out to your target machine, and run it with ./a.out 10 to see
if your cross compiler is working correctly.
ps: there are a lot of prebuilt ARM toolchain you can use if you don't want
to build a cross toolchain yourself.
2. prepare a script named "gcc" that wraps your cross gcc, for example,
#!/bin/sh
/path/to/gcc-arm "$@"
But, don't add it to $PATH yet (don't forget to "chmod +x gcc").
3. bootstrap Go, assuming you're in $GOROOT/src:
# first, do a simple non-cgo cross go build:
GOARCH=arm GOOS=linux ./make.bash
4. we need to trick cmd/go into thinking we are doing native compile so that
it will allow us to enable cgo:
PATH=/path/to/your/gcc/wrapper:$PATH GOARCH=arm \
GOOS=linux CGO_ENABLED=1 ../bin/go install -a -v std
ps: after this step, you not only have a cross toolchain for ARM with cgo
support, you also have go/gofmt/godoc for your target machine in
$GOROOT/bin/linux_arm.
5. we are ready to do cross compiling now.
example usage:
PATH=/path/to/your/gcc/wrapper:$PATH GOARCH=arm \
GOOS=linux CGO_ENABLED=1 \
$GOROOT/bin/go build $GOROOT/misc/cgo/stdio/hello.go
of course, you only need to do step 1 to 4 once, and you can
use shell aliases or wrapper script to make your life easier to
cross develop Go.
PS: cmd/go don't allow you to cross compile on different OSes, and
it can't be tricked unless we change some code, for example, apply