为什么特定 CPU 的可执行程序不能在 Linux 和 Windows 上运行? [英] Why an executable program for a specific CPU does not work on Linux and Windows?

查看:33
本文介绍了为什么特定 CPU 的可执行程序不能在 Linux 和 Windows 上运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像 exe 这样的可执行问题在 Linux 上不起作用(没有 wine).编译源代码时,编译器会生成特定于特定 cpu 架构的目标代码.但是相同的应用程序不适用于具有相同 CPU 的另一个操作系统.我知道代码可能包含特定于操作系统的指令,这些指令会阻止可执行文件运行.但是一个简单的程序 2+2 呢?令人困惑的部分是机器代码阻止工作的地狱.特定于cpu的机器代码对吗?如果我们剥离可执行文件格式,我们能否看到两个操作系统的相同机器代码(如 2 + 2)?

An executable problem like exe does not work on Linux (without wine). When compiling source code compiler produce object code which is specific to a particular cpu architecture. But same application does not work with on an another OS with same CPU. I know code may include instructions to specific to the OS that will prevent executable running. But what about a simple program 2+2 ? Confusing part is what the hell that machine code prevents working. Machine code specific to cpu right? If we strip executable file format could we see same machine code (like 2 + 2) for both operating systems?

还有一个问题:汇编语言呢?windows 和 Linux 对同一个 cpu 使用不同的汇编语言吗?

One more question: What about assembly language? DO windows and Linux use different assembly language for same cpu?.

推荐答案

有很多不同.其中:

  1. 可执行格式:每个操作系统都要求二进制文件符合特定的二进制格式.对于 Windows,这是可移植可执行文件 (PE) 格式.对于 Linux,大部分时间都是 ELF(它也支持其他类型).

  1. Executable Format: Every OS requires the binaries to conform to a specific binary format. For Windows, this is Portable Executable (PE) format. For Linux, it's ELF most of the time (it supports other types too).

应用程序二进制接口:每个操作系统都定义了一组主要系统函数以及程序调用它们的方式.这在 Linux 和 Windows 之间有着根本的不同.虽然在 x86 架构的 Linux 和 Windows 上计算 2 + 2 的指令是相同的,但应用程序的启动方式、打印输出的方式以及退出方式在操作系统之间是不同的.

Application Binary Interface: Each OS defines a set of primary system functions and the way a program calls them. This is fundamentally different between Linux and Windows. While the instructions that compute 2 + 2 are identical on Linux and Windows in x86 architecture, the way the application starts, the way it prints out the output, and the way it exits differs between the operating systems.

是的,x86 架构的 Linux 和 Windows 程序都使用英特尔定义的 CPU 支持的指令集.

Yes, both Linux and Windows programs on x86 architecture use the instruction set that the CPU supports which is defined by Intel.

这篇关于为什么特定 CPU 的可执行程序不能在 Linux 和 Windows 上运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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