編譯為 x86 時檢測 OS x86 或 x64 (Detect OS x86 or x64, when compiled as x86)


問題描述

編譯為 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)

參考解法

方法 1:

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.

(by fladonuser253751)

參考文件

  1. Detect OS x86 or x64, when compiled as x86 (CC BY‑SA 2.5/3.0/4.0)

#32bit-64bit #GO #cross-platform #x86 #cpu-architecture






相關問題

Visual Studio 將非託管 64 位 DLL 複製到 SysWOW64 而不是 System32 (Unmanaged 64-bit DLL copied to SysWOW64 and not System32 by Visual Studio)

將 R 包從 32 位安裝到 64 位 (install R package from 32bit to 64bit)

x32 ABI - гэта інструмент, як ім карыстацца (x32 ABI is this a tool ,how to use this)

在 64 位應用程序中使用 32 位 .lib 庫 (Using 32bit .lib library in a 64bit application)

當構建配置為“AnyCPU”或“x64”時,Castle Windsor 無法解決 (Castle Windsor not resolving when build configuration is "AnyCPU" or "x64")

32 位 SPARC V8 應用程序可以在 64 位 SPARC V9 上運行嗎? (Can 32-bit SPARC V8 application run on 64-bit SPARC V9?)

Eclipse 內存分析器:無法附加到 32 位進程 (Eclipse Memory Analyzer: Unable to attach to 32-bit process)

如何知道 libpython27.a 是 32 位還是 64 位? (How to know whether libpython27.a is 32-bit or 64-bit?)

確定當前進程是否在 WOW64 中運行或不在 Go 中運行 (Determining if current process runs in WOW64 or not in Go)

確保在 Windows Server 2003 64 位上安裝了 ASP.NET 3.5 Framework (Ensure that ASP.NET 3.5 Framework is installed on Windows Server 2003 64-bit)

為什麼我可以從在 IIS7 中以 64 位模式運行的 AnyCPU .NET Web 應用程序調用 32 位 COM 庫? (Why am I able to call a 32 bit COM library from an AnyCPU .NET web application running in IIS7 in 64 bit mode?)

編譯為 x86 時檢測 OS x86 或 x64 (Detect OS x86 or x64, when compiled as x86)







留言討論