编译为 x86 时检测 OS x86 或 x64 [英] Detect OS x86 or x64, when compiled as x86
问题描述
我开发了引导软件来启动我的游戏.我用 Go 做到了这一点.跨平台对我来说尤其重要.另外,我不想将下载链接分成两个 x86/x64.我想在一个输出中处理所有事情.这就是我必须编译到 x86 的原因.当我这样做时,我无法正确检测到操作系统是 x86 还是 x64.
在编译为 x86 的软件中,我如何正确检测操作系统 x86 或 x64(在 Go 中).
编译为 x86 时,此代码不正确.
const is64Bit = uint64(^uintptr(0)) == ^uint64(0)
Windows 你可以调用IsWow64Process
来判断你是否是运行在64 位操作系统.请注意,如果您是在 64 位操作系统上运行的 64 位进程,它会返回 false,但如果您正在运行 64 位进程,那么您就知道该操作系统是 64 位的,否则它不会运行.>
另请注意,32 位 Windows 已过时.微软已经在逐步停止对 32 位 Windows 的支持——他们没有不再希望在新计算机上安装它.
在 Linux 上你可以调用 uname
并查看 machine
字段.这是可能值的列表.请注意,它们中的大多数与您的程序不兼容,只有 i386
、i686
和 x86_64
.
I developed bootstrap software to start my game. I did this with Go. It was especially important for me to be cross-platform. Also, I didn't want to divide the download links into two as x86 / x64. I wanted to handle everything in one output. That's why I had to compile to x86. When I do this, I cannot properly detect that the operating system is x86 or x64.
In a software compiled as x86, how can i properly detect operating system x86 or x64 (in Go).
This code is not correct when compiled as x86.
const is64Bit = uint64(^uintptr(0)) == ^uint64(0)
On Windows you can call IsWow64Process
to determine whether you are a 32-bit process running on a 64-bit OS. Note that it returns false if you are a 64-bit process running on a 64-bit OS, but if you have a 64-bit process running, then you know the OS is 64-bit or it wouldn't run.
Also note that 32-bit Windows is considered obsolete. Microsoft is already phasing out support for 32-bit Windows - they no longer want it to be installed on new computers.
On Linux you can call uname
and look at the machine
field. Here's a list of possible values. Note that most of them won't be compatible with your program, only i386
, i686
and x86_64
.
这篇关于编译为 x86 时检测 OS x86 或 x64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!