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

查看:31
本文介绍了如何确定程序是在 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.

相关:检测操作系统 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 for 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天全站免登陆