LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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



Reply
 
Search this Thread
Old 09-09-2008, 05:44 PM   #1
pmorg
LQ Newbie
 
Registered: Jun 2007
Location: Costa Rica
Distribution: Fedora 7
Posts: 18

Rep: Reputation: 0
compiling question


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?

That's got me scratching me head....
 
Old 09-09-2008, 06:02 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
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.
 
Old 09-09-2008, 06:30 PM   #3
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by CRC123 View Post
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.
 
Old 09-10-2008, 03:27 AM   #4
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
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.
 
  


Reply

Tags
basic, compiler


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling question conanm4 Linux - General 1 05-16-2008 01:02 PM
A question about compiling Tortanick Programming 2 11-05-2007 03:29 PM
A compiling question neily Linux - Security 1 09-24-2006 06:22 PM
compiling question glo Linux - Newbie 0 07-28-2003 11:50 AM
Compiling Question Bigun Linux - Software 2 01-03-2003 04:39 AM


All times are GMT -5. The time now is 11:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration