当编译为x86时,检测OS x86或x64 [英] Detect OS x86 or x64, when compiled as x86

查看:91
本文介绍了当编译为x86时,检测OS x86或x64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了引导程序软件来开始我的游戏.我是用Go完成的.跨平台对我来说尤其重要.另外,我不想将下载链接分为两个x86/x64.我想在一个输出中处理所有内容.这就是为什么我必须编译到x86的原因.当我这样做时,我无法正确检测到操作系统是x86或x64.

在编译为x86的软件中,如何正确检测操作系统x86或x64(在Go中).

当编译为x86时,此代码不正确.

  const is64Bit = uint64(^ uintptr(0))== ^ uint64(0) 

解决方案

在Windows上 Microsoft已经淘汰了对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屋!

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