Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are object files platform independent?

Is it possible to compile program on one platform and link with other ? What does object file contain ? Can we delink an executable to produce object file ?

like image 940
Xinus Avatar asked Jan 23 '10 14:01

Xinus


People also ask

What is the difference between object file and binary file?

An object file contains the same instructions in machine-readable, binary form. Assembly files can be translated to object files by the assembler (as). An LLVM bitcode file (. bc) contains LLVM instructions in binary form.

Is C language platform dependent or independent?

C is a portable programming language If you write a C code in your machine, it will run on any machine which supports C, without modifying a single line of code. Because it is not tied to any hardware or system. We can say, it is a hardware independent language or platform independent language.

How do object files work?

An object file is a computer file containing object code, that is, machine code output of an assembler or compiler. The object code is usually relocatable, and not usually directly executable. There are various formats for object files, and the same machine code can be packaged in different object file formats.

Is object file the same as executable?

The main difference between object file and executable file is that an object file is a file generated after compiling the source code while an executable file is a file generated after linking a set of object files together using a linker. C is a general-purpose, high-level programming language.


1 Answers

No. In general object file formats might be the same, e.g. ELF, but the contents of the object files will vary from system to system.

An object file contains stuff like:

Object code that implements the desired functionality A symbol table that can be used to resolve references Relocation information to allow the linker to locate the object code in memory Debugging information 

The object code is usually not only processor specific, but also OS specific if, for example, it contains system calls.


Edit:
Is it possible to compile program on one platform and link with other ? 

Absolutely. If you use a cross-compiler. This compiler specifically targets a platform and generates object files (and programs) that are compatible with the target platform. So you can use an X86 Linux system, for example, to make programs for a powerpc or ARM based system using the appropriate cross compiler. I do it here.

like image 116
Richard Pennington Avatar answered Oct 14 '22 16:10

Richard Pennington