What’s the difference between a Windows compiler and Linux executable

Asked

Viewed 169 times

4

When compiling a simple program for Linux, the compiler generates an executable that only works on Linux, but when compiling the same code with a compiler for Windows it generates an executable that only works for Windows. What I want to know is what difference the compilation process in the 2 operating systems ?

If the code is the same, why is the end result different ? What part of the build that starts the differences ? is in the link part ? and why there are these differences ?

  • https://stackoverflow.com/questions/32117572/why-does-a-linux-compiled-program-not-work-on-windows

  • 1

    I understood, but well that someone could answer in Portuguese to help the popular Brazilian version of Stackoverflow

1 answer

3


This answer is simplistic, but it tries to give an idea. Imagine that programs are a list of requests to do something.

Just like in a restaurant where Voce makes the order informing that either well-done, with or without onions, ..., this is just the order (your program). Who will actually prepare the dish (the operating system kernel) is in the kitchen tries to prepare according to your request (the program).

You’ll only eat what you want if you say the same about the cook.

The linux cook speaks ELF and the windows one speaks PE. So usually one does not understand the requests made to the other.

But there are some who are bilingual and can understand other formats. A very cool project is the Wine running windows on linux (sometimes performing better than windows itself).

So it’s just a matter of understanding the language to communicate with the operating system.

Here is a link to some executable format types (in Spanish, but I think you can get an idea that has a lot)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.