Posts

Showing posts from 2018

Compiler, Obect Code / Relocatable Code, Linker

Image
When we compile a C source file using GNU C compiler, it compiles our code into an assembly source. Then, the assembly source is assembled by the assembler (included with gcc (GNU C compiler)). It generates the object code (relocatable format machine code), and it is usually not directly executable. Next, the linker links libraries. Libraries are also in relocatable format, this is why we compile libraries with -shared / -fpic / -fPIC flags. The linking process checks the library name that we included in the source file and it also checks whether the library is available in the system's default library path /usr/lib (GNU/Linux) if not, we can pass the specific libraries as an argument to gcc with -I flag (gcc -I/home/shuja/Documents/libmy.so )  finally, the linker links our sources(object codes) with libraries and generates the executable. C Source File  Assembly Source (generated  by GNU C compiler) Disassembled object code (Disassembled because object code isn't