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

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

问题描述

像exe这样的可执行文件不能在Linux上运行(没有酒).编译源代码时,编译器会生成特定于特定cpu体系结构的目标代码.但是,同一应用程序不能在具有相同CPU的另一个OS上使用.我知道代码可能包含特定于操作系统的指令,这将阻止可执行文件运行.但是一个简单的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程序均使用Intel支持的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天全站免登陆