如何确定该程序是在Go中构建为32位还是64位? [英] How do I determine whether the program was built as 32 bit or 64 bit in Go?

查看:64
本文介绍了如何确定该程序是在Go中构建为32位还是64位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能得到的最接近的是 runtime.GOARCH ,但这也可能会给出 arm ,它可以是32位或64位.

The closest I can get is runtime.GOARCH, but that might also give arm, which could be either 32 or 64 bit.

我只关心程序的构建方式,而不关心操作系统是否还支持64位可执行文件.例如对于AArch64 CPU上的ARM模式或x86-64 CPU上的32位兼容模式,我仍然需要32,因为这是程序运行的模式.

I only care how this program was built, not whether the OS also supports 64-bit executables. e.g. for ARM mode on an AArch64 CPU or 32-bit compat mode on an x86-64 CPU, I still want 32 because that's the mode this program is running in.

相关:检测OS x86或x64,当在GO中以x86编译时是关于检测操作系统支持的内容,例如可能会运行不同编译的可执行文件.

Related: Detect OS x86 or x64, when compiled as x86 in GO is about detecting what the OS supports, e.g. for maybe running a differently-compiled executable.

推荐答案

将GOARCH用于arm:arm(ARM)和arm64(AArch64),

Use GOARCH for arm: arm (ARM) and arm64 (AArch64),

可选环境变量

$ GOOS和$ GOARCH

$GOOS and $GOARCH

目标操作系统和编译体系结构的名称.它们分别默认为$ GOHOSTOS和$ GOHOSTARCH的值(如下所述).

The name of the target operating system and compilation architecture. These default to the values of $GOHOSTOS and $GOHOSTARCH respectively (described below).

$ GOOS的选择是

Choices for $GOOS are

$GOOS     $GOARCH
darwin    386
darwin    amd64
darwin    arm
darwin    arm64
dragonfly     amd64
freebsd   386
freebsd   amd64
freebsd   arm
linux     386
linux     amd64
linux     arm
linux     arm64
linux     ppc64
linux     ppc64le
linux     mips64
linux     mips64le
netbsd    386
netbsd    amd64
netbsd    arm
openbsd   386
openbsd   amd64
openbsd   arm
plan9     386
plan9     amd64
solaris   amd64
windows   386
windows   amd64

这篇关于如何确定该程序是在Go中构建为32位还是64位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆