Siu*_*ji- 6 android cross-compiling go cgo
adb shell
0. Go(Golang)来源
package main
import (
"fmt"
)
func main() {
fmt.Println("Hello, world!")
}
1A.构建命令
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build .
1B.输出(换行重新排列以防止滚动条)
# github.com/asukakenji/cross
warning: unable to find runtime/cgo.a
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file
/var/folders/dd/6k6vkzbd6d5803xj9zkjdhmh0000gn/T/go-link-150305609/go.o,
file was built for unsupported file format
( 0x7F 0x45 0x4C 0x46 0x01 0x01 0x01 0x00
0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
which is not the architecture being linked (x86_64):
/var/folders/dd/6k6vkzbd6d5803xj9zkjdhmh0000gn/T/go-link-150305609/go.o
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1C.再一次构建命令
以下命令给出相同的结果:
$ env CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build .
2.构建命令(详细)
"-v"
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 go build \
-x -ldflags "-extldflags -v" .
go buildclangXcode
3A.构建命令(成功,但......)
$CC
$ CGO_ENABLED=0 GOOS=android GOARCH=arm GOARM=7 \
CC=/path/to/arm-linux-androideabi/bin/clang go build .
arm-linux-androideabimake_standalone_toolchain.pymake-standalone-toolchain.sh
3B.输出
cross
# github.com/asukakenji/cross
warning: unable to find runtime/cgo.a
adb pushadb shell
我的问题
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build .
谢谢!