[cofface]Android使用Windows golang编译ELF

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/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
freebsd/amd64
freebsd/arm
freebsd/arm64
illumos/amd64
js/wasm
linux/386
linux/amd64
linux/arm
linux/arm64
linux/mips
linux/mips64
linux/mips64le
linux/mipsle
linux/ppc64
linux/ppc64le
linux/riscv64
linux/s390x
netbsd/386
netbsd/amd64
netbsd/arm
netbsd/arm64
openbsd/386
openbsd/amd64
openbsd/arm
openbsd/arm64
plan9/386
plan9/amd64
plan9/arm
solaris/amd64
windows/386
windows/amd64
windows/arm

3、设置编译android ELF,NDK以android-ndk-r21b版本为例:

SET CGO_ENABLED=1
SET GOOS=android
SET GOARCH=arm
set CC=$NDK路径\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang.cmd
set CXX=$NDK路径\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi19-clang++.cmd
4、编译:
go build test.go文件

 

转载请注明来源:Cofface Blog » [cofface]Android使用Windows golang编译ELF

赞 (9) 打赏

感谢您的支持,我会继续努力的!

支付宝扫一扫打赏

微信扫一扫打赏