Windows下使用golang编译android ELF可执行文件:
1、下载安装golang,安装完会自动配置环境变量,下载地址:https://golang.org/doc/install?download=go1.15.5.windows-amd64.msi
2、安装完后查看golang版本号,命令提示符下操作以下命令:
go version
返回go version go1.15.5 windows/amd64表示安装配置环境成功;
3、查看支持的交叉编译平台:
go tool dist list
aix/ppc64android/386android/amd64android/armandroid/arm64darwin/amd64darwin/arm64dragonfly/amd64freebsd/386freebsd/amd64freebsd/armfreebsd/arm64illumos/amd64js/wasmlinux/386linux/amd64linux/armlinux/arm64linux/mipslinux/mips64linux/mips64lelinux/mipslelinux/ppc64linux/ppc64lelinux/riscv64linux/s390xnetbsd/386netbsd/amd64netbsd/armnetbsd/arm64openbsd/386openbsd/amd64openbsd/armopenbsd/arm64plan9/386plan9/amd64plan9/armsolaris/amd64windows/386windows/amd64windows/arm
3、设置编译android ELF,NDK以android-ndk-r21b版本为例:
SET CGO_ENABLED=1SET GOOS=androidSET GOARCH=armset CC=$NDK路径\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.cmdset CXX=$NDK路径\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang++.cmd
go build test.go文件