From 6719d4c197b29e862c12ac729356d6f6325d9561 Mon Sep 17 00:00:00 2001 From: Rizkallah <rouba.rizkallah@etu.unistra.fr> Date: Wed, 20 Mar 2024 11:22:19 +0100 Subject: [PATCH] Task3 Done --- ex1/Exercise_1_T4 | 3 +++ ex1/Exercise_1_Task_3 | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 ex1/Exercise_1_T4 diff --git a/ex1/Exercise_1_T4 b/ex1/Exercise_1_T4 new file mode 100644 index 0000000..d6fa670 --- /dev/null +++ b/ex1/Exercise_1_T4 @@ -0,0 +1,3 @@ +Compiling translates C code into object code without including the code of functions and variables from external libraries (such as stdio or stdlib) and files. + +Linking will take all the previously created object code files and combine them together, along with the code of functions and variables from external libraries, resulting in a working executable file. \ No newline at end of file diff --git a/ex1/Exercise_1_Task_3 b/ex1/Exercise_1_Task_3 index 34c89e8..764d19b 100644 --- a/ex1/Exercise_1_Task_3 +++ b/ex1/Exercise_1_Task_3 @@ -1,7 +1,17 @@ Output report: -In all three cases the program takes an input array that is : 5 9 1 2 3. -In cases 1 and 3 the array is sorted in the ascendant order with an output being 1 2 3 5 9. +In all three cases the program takes an input array that is: 5 9 1 2 3 +In cases 1 and 3 the array is sorted in the ascending order with an output being: 1 2 3 5 9 Whereas in case 2 the array is sorted in the descending order with an output being: 9 5 3 2 1 -When compiling L1 the -c option says not to run the linker to get object files as output. -Assembling and Linking +That is due to the fact L1, L2 and L3 are not compiled with the same libraries. + + + +When compiling L1 and L2 the -c option says not to run the linker to just produce object files as output from the C files l1.c and l2.c which are then linked to the object file created by compiling T3.c in the second gcc command. +In L1 and L2 the produced object files are linked to two different libraries which causes the array to be sorted in different orders. +In L3 there is no linking, all the c files, including the one that was used to create the library libmylib1.a are given to the compiler which produces an executable. So the same sorting function is applied at the end in L1 and L3 even though the compilation process isn't exactly the same (with and without creating and linking a library) that's why their outputs are identical. +The library mylib1 from l1.c sorts in the ascending order and mylib2 from l2.c sorts in the descending order. + + + +Starting libraries name with "lib" is a naming convention, this part of the name can then be dropped at the linking phase indicated when specifing the folder in which to look in for the library with -L and the library's name with -l<library name>. -- GitLab