不同的EXE如何在正确的运行时运行?
我一直很好奇一个扩展,EXE,如何能够如此通用,因为如果你汇编一个汇编程序,你会得到一个适用于你的处理器的机器代码中的 EXE,但如果你编译一个 C# 或其他 .Net程序,您还可以获得一个 EXE,只不过它是在适当的运行时环境中运行的。我不确定这是否因操作系统而异(我想是的),但是当执行 EXE 时,它是如何确定如何执行它的?
与此相关的是,如果我编写自己的编程语言,我将如何将运行时环境与此机制结合起来?
I've always been curious as to how one extension, EXE, can be as versatile as it is in that if you assemble an assembly program, you get an EXE in machine code for your processor but if you compile a C# or other .Net program, you also get an EXE except that it is run in the proper runtime environment. I'm not sure if this is different from OS to OS (I imagine it is), but when an EXE is executed, how is it determined how to execute it?
On a related note, if I were writing my own programming language, how would I tie in my runtime environment into this mechanism?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 .NET 程序编译为 EXE 时,它不仅仅是一团字节码(如 Java)。实际上创建了本机可执行文件,它将加载 .NET 运行时并将 .NET 字节码移交给它,或者显示一条友好的错误消息,指示该框架不可用。
该格式比这更灵活,因为每个 Windows EXE 实际上在开头都包含一个 DOS 程序,当作为 DOS 程序执行时,该程序将显示错误(“无法在 DOS 模式下运行”)。
您可以在 Wikipedia 上阅读有关 PE 格式的更多详细信息: http://en.wikipedia.org/wiki/可移植_可执行文件
When compiling a .NET program to an EXE, it's more than just a blob of bytecode (like Java). There's actually native executable created that will load the .NET runtime and hand off the .NET bytecode to it, or display a friendly-ish error message indicating that the framework is not available.
The format is even more flexible than that, as every Windows EXE actually includes a DOS program at the beginning which will display an error ("cannot run in DOS mode") when executed as a DOS program.
You can read more details on the PE format on Wikipedia: http://en.wikipedia.org/wiki/Portable_Executable