Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Probably simple...but a question I've often wondered about.
So...I write a program in some language and compile it. As I understand it what has happened is my code (in whatever language) is converted to the codes (like ops codes, though I understand the difference) for the relevant chip. So my ops codes for Z80 will not work for an Intel x86 chip. But, an x86 chip should be an x86 chip...right? If I write a program in (my case) BASIC and compile it in (my case) WIN98 why would the resulting compiled file NOT work in Linux? Same chip...even same computer. Different OS. Why would that matter?
It's all about format of the file. Windows executable use the PE format while Linux uses ELF format. They are incompatible. When a program is loaded, certain things are 'primed' on the CPU and system; access to memory is set up a certain way, the stack is said up a certain way, and various other things are setup a certain way. An example maybe where a windows program may expect some bits to be in a certain cpu register (say EAX) while the Linux binary may expect that data in a different register (Say EBX) etc.
It's all about format of the file. Windows executable use the PE format while Linux uses ELF format. They are incompatible. When a program is loaded, certain things are 'primed' on the CPU and system; access to memory is set up a certain way, the stack is said up a certain way, and various other things are setup a certain way. An example maybe where a windows program may expect some bits to be in a certain cpu register (say EAX) while the Linux binary may expect that data in a different register (Say EBX) etc.
It's not only about file format. Any executable file calls to external system functions, and they are operating-system specific.
Yes, you see, any operating-system creates an environment in which programs run. This takes the form of a collection of "libraries" containing truly-vast amounts of code that programs can simply use.
There are many hundreds of these associated with any operating-system, and every program is utterly-dependent upon them to do almost everything.
These libraries are not implemented the same way from one system to another. You therefore either have to compile the program for the target system or, in the specific case of Windows software, you might be able to use a compatibility-layer called "Wine."
Wine, itself, is a great example of just how different two systems can be... and how complex the seemingly-simple notion of "compatibility layer" can actually be to implement. It, alone, consists of a vast amount of source-code... and it doesn't even come close to replicating the entire Windows environment.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.