Flow of building a program (2 of 2)Objectcode:hello.oAssemblycode:hello.sAssembler"as"in Linux.Linker"Id"in Linux.Static/DynamicExecutable:hellolibrary11
Flow of building a program (2 of 2) 11 Assembly code: hello.s Assembler “as” in Linux. Linker “ld” in Linux. Object code: hello.o Executable: hello Static/Dynamic library
(Still...2 of 2) Assembler and Linker. The assembler assembles“hello.s"andgenerates an object code “hello.o"- A step closer to machine code-Try:“as hello.s -o hello.o" The linker puts together all object files as well asthe libraries- There are two kinds of libraries: statically-linked anddynamically-linked ones12
(Still.2 of 2) Assembler and Linker • The assembler assembles “hello.s” and generates an object code “hello.o” – A step closer to machine code – Try: “as hello.s –o hello.o” • The linker puts together all object files as well as the libraries – There are two kinds of libraries: statically-linked and dynamically-linked ones 12
Sidetrack:LibraryfilesA library file is... just a bunch of function implementations. for the linker to look for the function(s) that the target Cprogram needs.Shared librarywith".so"filegcc -sharedextension.SCAstatic librarywith".a"filearextension.Itisalso called anAbunchof“dot-o"files.archive.13
Sidetrack: Library files • A library file is. – just a bunch of function implementations. – for the linker to look for the function(s) that the target C program needs. 13 A bunch of “dot-o” files. Shared library with “.so” file extension. A static library with “.a” file extension. It is also called an archive. .so .a
Sidetrack:Library filesSeThe finalThe linker onlyprogramisthecheckswhetherthecombinationoffunctionsusedin".o"filesexistsintheabovetwocodes.the"so"files ornot.EAsmallerprogram!Linking withstatic libraryfileLinking with dynamic library file14
Sidetrack: Library files 14 .a .so Linking with static library file. .o .o The final program is the combination of the above two codes. The linker only checks whether the functions used in “.o” files exists in the “.so” files or not. A smaller program! Linking with dynamic library file
How to compile multiple files? gcc by default hides all the intermediate steps.-Executable:“gcc -o hello hello.c"generates"hello"directly.-Obiect code:“gcc -c hello.c" generates“hello.o"directly. How about working with multiple files?15
How to compile multiple files? • gcc by default hides all the intermediate steps. – Executable: “gcc -o hello hello.c” generates “hello” directly. – Object code: “gcc -c hello.c” generates “hello.o” directly. • How about working with multiple files? 15