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 ?
No. They are not platform independent. Take for instance, the GNU C Compiler (gcc), that generates ELF binary files. Windows compilers (Borland, Microsoft, Open Watcom) can produce Windows Binary PE (Portable Executable) format. Novell binaries are NLM (Netware Loadabable Module) format.
These examples above of the different outputs which is compiler dependant, there is no way, a linker on a Windows platform, would know anything about ELF format nor NLM format, hence it is impossible to combine different formats to produce an executable that can run on any platform.
Take the Apple's Mac OSX (before the Intel chips were put in), they were running on the PowerPC platform, even if it has the GNU C Compiler, the binary is specifically for the PowerPC platform, if you were to take that binary and copy it onto a Linux platform, it will not run as a result of the differences in the instructions of the platform's microprocessor i.e. PowerPC.
Again, same principle would apply to the OS/390 mainframe system, a GNU C compiler that produces a binary for that platform will not run on an pre-Intel Apple Mac OSX.
Edit: To further clarify what an ELF format would look like see below, this was obtained by running objdump -s main.o under Linux.
main.o: file format elf32-i386 Contents of section .text: 0000 8d4c2404 83e4f0ff 71fc5589 e55183ec .L$.....q.U..Q.. 0010 14894df4 a1000000 00a30000 0000a100 ..M............. 0020 000000a3 00000000 8b45f483 38010f8e .........E..8... 0030 9c000000 8b55f48b 420483c0 048b0083 .....U..B....... 0040 ec086800 00000050 e8fcffff ff83c410 ..h....P........ 0050 a3000000 00a10000 000085c0 7520a100 ............u .. 0060 00000050 6a1f6a01 68040000 00e8fcff ...Pj.j.h....... 0070 ffff83c4 10c745f8 01000000 eb5a8b45 ......E......Z.E 0080 f4833802 7e218b55 f48b4204 83c0088b ..8.~!.U..B..... 0090 0083ec08 68240000 0050e8fc ffffff83 ....h$...P...... 00a0 c410a300 000000a1 00000000 85c07520 ..............u 00b0 a1000000 00506a20 6a016828 000000e8 .....Pj j.h(.... 00c0 fcffffff 83c410c7 45f80100 0000eb08 ........E....... 00d0 e8fcffff ff8945f8 8b45f88b 4dfcc98d ......E..E..M... 00e0 61fcc3 a.. Contents of section .rodata: 0000 72000000 4552524f 52202d20 63616e6e r...ERROR - cann 0010 6f74206f 70656e20 696e7075 74206669 ot open input fi 0020 6c650a00 77000000 4552524f 52202d20 le..w...ERROR - 0030 63616e6e 6f74206f 70656e20 6f757470 cannot open outp 0040 75742066 696c650a 00 ut file.. Contents of section .comment: 0000 00474343 3a202847 4e552920 342e322e .GCC: (GNU) 4.2. 0010 3400 4.
Now compare that to a PE format for a simple DLL
C:\Program Files\Microsoft Visual Studio 9.0\VC\bin>dumpbin /summary "C:\Documents and Settings\Tom\My Documents\Visual Studio 2008\Projects\SimpleLib\Release\SimpleLib.dll"
Microsoft (R) COFF/PE Dumper Version 9.00.30729.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file C:\Documents and Settings\Tom\My Documents\Visual Studio 2008\Projects\SimpleLib\Release\SimpleLib.dll
File Type: DLL
Summary
1000 .data
1000 .rdata
1000 .reloc
1000 .rsrc
1000 .text
Notice the differences in the sections, under ELF, there is .bss, .text, .rodata and .comment, and is an ELF format for i386 processor.
Hope this helps, Best regards, Tom.