什么是交叉编译器和跨平台?

时间:2021-12-26 02:43:00

I am bit confused with the terms of cross platform and cross compiler. Let me be first clear about the cross platform. When people talk about cross platform it means the architecture of the CPU, i.e, X86 and X64 ? or the OS i.e windows 32 bit or Windows 64 (server or desktop)? UNIX doesn't have different flavours like 64 bit or 32 bit. Why so?

我对跨平台和交叉编译器的术语有点困惑。让我首先明确跨平台。当人们谈论跨平台时,它意味着CPU的架构,即X86和X64?或OS,即Windows 32位或Windows 64(服务器或桌面)? UNIX没有64位或32位等不同的版本。为什么这样?

.NET and java is cross compiler language, what it means? When the program is compiled in .NET, we have to choose the option like X86, X64 or Any CPU. What that means? Also in setup project we have to choose the option between x86 and x64. So if the program is compiled in x86 and msi file has been created on x64 will it run on both X64 and x86 or any one of ?

.NET和java是交叉编译语言,这意味着什么?当程序在.NET中编译时,我们必须选择X86,X64或Any CPU等选项。那意味着什么?同样在安装项目中,我们必须选择x86和x64之间的选项。因此,如果程序是在x86中编译的,并且在x64上创建了msi文件,那么它将在X64和x86上运行,还是在任何一个上运行?

5 个解决方案

#1


When people talk about cross platform it means the architecture of the CPU, i.e, X86 and X64 ? or the OS

当人们谈论跨平台时,它意味着CPU的架构,即X86和X64?或操作系统

Both. It usually means sotfware that runs in a virtual machine or software that is compiled for each platform separately.

都。它通常表示在虚拟机中运行的sotfware或为每个平台单独编译的软件。

UNIX doesn't have different flavours like 64 bit or 32 bit.

UNIX没有64位或32位等不同的版本。

It does.

So if the program is compiled in x86 and msi file has been created on x64 will it run on both X64 and x86 or any one of ?

因此,如果程序是在x86中编译的,并且在x64上创建了msi文件,那么它将在X64和x86上运行,还是在任何一个上运行?

If you target x86, amd64 will also run the code (in 32 bit mode). It shouldn't matter where you create the installer msi file.

如果你的目标是x86,amd64也将运行代码(在32位模式下)。在哪里创建安装程序msi文件无关紧要。

Cross compiling means that the host and target platform are not the same. For example building windows software on a Linux computer.

交叉编译意味着主机和目标平台不同。例如,在Linux计算机上构建Windows软件。

#2


Cross-platform refers to the ability of a program to run on multiple different platforms. Cross-platform code frequently uses various toolkits/languages to achieve this (Qt, Flash, etc.)

跨平台是指程序在多个不同平台上运行的能力。跨平台代码经常使用各种工具包/语言来实现这一目标(Qt,Flash等)

Cross-compiler is a compiler which generates code for a platform different than the platform on which the compiler itself runs. Compilers for embedded targets are almost always cross-compilers, since few embedded targets are capable of hosting the compiler itself.

交叉编译器是一种编译器,它为不同于编译器本身运行的平台的平台生成代码。嵌入式目标的编译器几乎总是交叉编译器,因为很少有嵌入式目标能够托管编译器本身。

Cross-compilers requires a build system which does not assume that the host and target system are compatible, i.e. you cannot run a target executable at build time, for example to figure out runtime aspects of the generated code (such as word size).

交叉编译器需要一个构建系统,它不假定主机和目标系统是兼容的,即你不能在构建时运行目标可执行文件,例如找出生成代码的运行时方面(例如字大小)。

(Cross-compilation can also be applied to the compiler itself. This is referred to as Canadian Cross compilation, which is a technique for building a (cross-)compiler on host different from the one the compiler should be run on. In this case we have three platforms:

(交叉编译也可以应用于编译器本身。这被称为加拿大交叉编译,这是一种在主机上构建(交叉)编译器的技术,不同于编译器应该运行的编译器。在这种情况下我们有三个平台:

  • The platform the compiler is built on (build).
  • 编译器构建的平台(构建)。

  • The platform which hosts the compiler (host).
  • 托管编译器(主机)的平台。

  • The platform for which the compiler generates code (target).
  • 编译器生成代码(目标)的平台。

I suspect that most programmers will never encounter this.)

我怀疑大多数程序员都不会遇到这种情况。)

#3


Cross platform, I suppose, could indicate that it runs on either Windows/Mac/*nix or that it runs on either x86/x86_64/ARM/PPC, but unless otherwise stated I believe that it generally means that it runs on the different operating systems. For example "Java apps are cross-platform" this usually applies to the fact that Java apps can run on Win/Mac/*nix.

我想,跨平台可能表明它在Windows / Mac / * nix上运行,或者在x86 / x86_64 / ARM / PPC上运行,但除非另有说明,否则我认为它通常意味着它在不同的操作上运行系统。例如,“Java应用程序是跨平台的”,这通常适用于Java应用程序可以在Win / Mac / * nix上运行的事实。

#4


'cross platform' refers to things working on many different platforms, so that may be OS, or CPU (type (x86/MIPS) or bit size (32/64)). This does not imply if a rebuilt is required to run on the other platforms just that is can, eg QT can target many platforms but you application may need rebuilding on each, or you may be able to build once, like java or .Net

“跨平台”是指在许多不同平台上工作的东西,因此可能是OS或CPU(类型(x86 / MIPS)或位大小(32/64))。这并不意味着如果需要重建才能在其他平台上运行,例如QT可以针对许多平台,但是应用程序可能需要在每个平台上进行重建,或者您可能能够构建一次,如java或.Net

'cross compiler' means a compiler on this platform that makes a program that can run on another platform. Thus build WinCE executables on Win32. Or you may build an Linux application on a window box, by building a version of GCC that runs in windows, but thats output target is Linux/Elf. If you have an embedded device you nearly always cross-compile to build the target executable.

“交叉编译器”是指此平台上的编译器,它使程序可以在另一个平台上运行。从而在Win32上构建WinCE可执行文件。或者您可以通过构建在Windows中运行的GCC版本在窗口框上构建Linux应用程序,但那个输出目标是Linux / Elf。如果您有嵌入式设备,则几乎总是交叉编译以构建目标可执行文件。

X86, X64 or Any CPU. What that means? It controls how the .Net app is targeted to one architecture or not, if you target then it won't run on both, but the compiler many make some optimizations. If it's non-targets (Any CPU) it will run on both. This is mainly useful if you directly call into external .dll's and you hard link the 64bit or 32bit version, and therefore only want your application to run in the same environment.

X86,X64或任何CPU。那意味着什么?它控制着.Net应用程序是如何针对一个体系结构的,如果你的目标是它不会在两者上运行,但编译器会进行一些优化。如果它是非目标(任何CPU),它将在两者上运行。如果您直接调用外部.dll并且您硬链接64位或32位版本,这非常有用,因此只希望您的应用程序在相同的环境中运行。

On the installers front Windows 64bit can run 32bit applications and 32bit installers, where-as 64bit applications cannot run on 32bit systems. On other platforms you normally rebuild the code for the architecture your running (Linux) or on the Mac you download universal executables (which I think have multiple targeted builds inside)

在安装程序方面,Windows 64bit可以运行32位应用程序和32位安装程序,因为64位应用程序无法在32位系统上运行。在其他平台上,您通常会重建正在运行的体系结构(Linux)的代码,或者在Mac上重新下载通用可执行文件(我认为其中有多个目标构建)

#5


Native Compilers: Native compilers are those which generates the executable files from the source code which in turn will execute on the same system on which compiler is available.

本机编译器:本机编译器是从源代码生成可执行文件的源代码,后者又将在可用编译器的同一系统上执行。

Cross Compiler: Cross compilers are those which generate the executable files from the source code which in turn will execute on some different system then on which compiler is available.

交叉编译器:交叉编译器是那些从源代码生成可执行文件的编译器,后者将在某个不同的系统上执行,然后在哪个编译器可用。

Find examples on native and cross compilers on BoundsCheck

在BoundsCheck上查找本机和交叉编译器的示例

#1


When people talk about cross platform it means the architecture of the CPU, i.e, X86 and X64 ? or the OS

当人们谈论跨平台时,它意味着CPU的架构,即X86和X64?或操作系统

Both. It usually means sotfware that runs in a virtual machine or software that is compiled for each platform separately.

都。它通常表示在虚拟机中运行的sotfware或为每个平台单独编译的软件。

UNIX doesn't have different flavours like 64 bit or 32 bit.

UNIX没有64位或32位等不同的版本。

It does.

So if the program is compiled in x86 and msi file has been created on x64 will it run on both X64 and x86 or any one of ?

因此,如果程序是在x86中编译的,并且在x64上创建了msi文件,那么它将在X64和x86上运行,还是在任何一个上运行?

If you target x86, amd64 will also run the code (in 32 bit mode). It shouldn't matter where you create the installer msi file.

如果你的目标是x86,amd64也将运行代码(在32位模式下)。在哪里创建安装程序msi文件无关紧要。

Cross compiling means that the host and target platform are not the same. For example building windows software on a Linux computer.

交叉编译意味着主机和目标平台不同。例如,在Linux计算机上构建Windows软件。

#2


Cross-platform refers to the ability of a program to run on multiple different platforms. Cross-platform code frequently uses various toolkits/languages to achieve this (Qt, Flash, etc.)

跨平台是指程序在多个不同平台上运行的能力。跨平台代码经常使用各种工具包/语言来实现这一目标(Qt,Flash等)

Cross-compiler is a compiler which generates code for a platform different than the platform on which the compiler itself runs. Compilers for embedded targets are almost always cross-compilers, since few embedded targets are capable of hosting the compiler itself.

交叉编译器是一种编译器,它为不同于编译器本身运行的平台的平台生成代码。嵌入式目标的编译器几乎总是交叉编译器,因为很少有嵌入式目标能够托管编译器本身。

Cross-compilers requires a build system which does not assume that the host and target system are compatible, i.e. you cannot run a target executable at build time, for example to figure out runtime aspects of the generated code (such as word size).

交叉编译器需要一个构建系统,它不假定主机和目标系统是兼容的,即你不能在构建时运行目标可执行文件,例如找出生成代码的运行时方面(例如字大小)。

(Cross-compilation can also be applied to the compiler itself. This is referred to as Canadian Cross compilation, which is a technique for building a (cross-)compiler on host different from the one the compiler should be run on. In this case we have three platforms:

(交叉编译也可以应用于编译器本身。这被称为加拿大交叉编译,这是一种在主机上构建(交叉)编译器的技术,不同于编译器应该运行的编译器。在这种情况下我们有三个平台:

  • The platform the compiler is built on (build).
  • 编译器构建的平台(构建)。

  • The platform which hosts the compiler (host).
  • 托管编译器(主机)的平台。

  • The platform for which the compiler generates code (target).
  • 编译器生成代码(目标)的平台。

I suspect that most programmers will never encounter this.)

我怀疑大多数程序员都不会遇到这种情况。)

#3


Cross platform, I suppose, could indicate that it runs on either Windows/Mac/*nix or that it runs on either x86/x86_64/ARM/PPC, but unless otherwise stated I believe that it generally means that it runs on the different operating systems. For example "Java apps are cross-platform" this usually applies to the fact that Java apps can run on Win/Mac/*nix.

我想,跨平台可能表明它在Windows / Mac / * nix上运行,或者在x86 / x86_64 / ARM / PPC上运行,但除非另有说明,否则我认为它通常意味着它在不同的操作上运行系统。例如,“Java应用程序是跨平台的”,这通常适用于Java应用程序可以在Win / Mac / * nix上运行的事实。

#4


'cross platform' refers to things working on many different platforms, so that may be OS, or CPU (type (x86/MIPS) or bit size (32/64)). This does not imply if a rebuilt is required to run on the other platforms just that is can, eg QT can target many platforms but you application may need rebuilding on each, or you may be able to build once, like java or .Net

“跨平台”是指在许多不同平台上工作的东西,因此可能是OS或CPU(类型(x86 / MIPS)或位大小(32/64))。这并不意味着如果需要重建才能在其他平台上运行,例如QT可以针对许多平台,但是应用程序可能需要在每个平台上进行重建,或者您可能能够构建一次,如java或.Net

'cross compiler' means a compiler on this platform that makes a program that can run on another platform. Thus build WinCE executables on Win32. Or you may build an Linux application on a window box, by building a version of GCC that runs in windows, but thats output target is Linux/Elf. If you have an embedded device you nearly always cross-compile to build the target executable.

“交叉编译器”是指此平台上的编译器,它使程序可以在另一个平台上运行。从而在Win32上构建WinCE可执行文件。或者您可以通过构建在Windows中运行的GCC版本在窗口框上构建Linux应用程序,但那个输出目标是Linux / Elf。如果您有嵌入式设备,则几乎总是交叉编译以构建目标可执行文件。

X86, X64 or Any CPU. What that means? It controls how the .Net app is targeted to one architecture or not, if you target then it won't run on both, but the compiler many make some optimizations. If it's non-targets (Any CPU) it will run on both. This is mainly useful if you directly call into external .dll's and you hard link the 64bit or 32bit version, and therefore only want your application to run in the same environment.

X86,X64或任何CPU。那意味着什么?它控制着.Net应用程序是如何针对一个体系结构的,如果你的目标是它不会在两者上运行,但编译器会进行一些优化。如果它是非目标(任何CPU),它将在两者上运行。如果您直接调用外部.dll并且您硬链接64位或32位版本,这非常有用,因此只希望您的应用程序在相同的环境中运行。

On the installers front Windows 64bit can run 32bit applications and 32bit installers, where-as 64bit applications cannot run on 32bit systems. On other platforms you normally rebuild the code for the architecture your running (Linux) or on the Mac you download universal executables (which I think have multiple targeted builds inside)

在安装程序方面,Windows 64bit可以运行32位应用程序和32位安装程序,因为64位应用程序无法在32位系统上运行。在其他平台上,您通常会重建正在运行的体系结构(Linux)的代码,或者在Mac上重新下载通用可执行文件(我认为其中有多个目标构建)

#5


Native Compilers: Native compilers are those which generates the executable files from the source code which in turn will execute on the same system on which compiler is available.

本机编译器:本机编译器是从源代码生成可执行文件的源代码,后者又将在可用编译器的同一系统上执行。

Cross Compiler: Cross compilers are those which generate the executable files from the source code which in turn will execute on some different system then on which compiler is available.

交叉编译器:交叉编译器是那些从源代码生成可执行文件的编译器,后者将在某个不同的系统上执行,然后在哪个编译器可用。

Find examples on native and cross compilers on BoundsCheck

在BoundsCheck上查找本机和交叉编译器的示例