Main

Lab 3

Objectives

Static and shared linking libraries, Executable and Linkable Format

Test Library

  • Create a folder lab3 and add it to your bitbucket server. Put all the files for this lab in this directory.

Work in pairs:

  • Student 1: Write a C function power(double a, double b) which computes a^b (b is the exponent). Put the function in power.c and the function signature in power.h.
  • Student 2: Write a C function factorial(int n) which computes n! . Put the function in factorial.c and the function signature in factorial.h.

Static Library

  • Write a make file (or directly use command line) to create a static library libpower.a for the power function (you may Google how to build a simple static library in C and how to use it. This page also might be helpful: http://www.adp-gmbh.ch/cpp/gcc/create_lib.html).
  • Put the libpower.a and .h files to a new directory static_test. Create a main file which uses the power function. Then compile and run. You should link the main file against the static library.

Shared Library

  • Write a make file (or directly use command line) to create a shared library libpower.so for the power function (you may Google how to build a simple shared library in C and how to use it. This page also might be helpful: http://www.adp-gmbh.ch/cpp/gcc/create_lib.html).
  • Put the libpower.so and .h files to a new directory shared_test. Create a main file which uses the polynomial function. Then compile and run. You should link the main file against the shared library.

Executable and Linkable Format

  • Write a bash script elf.sh which uses objdump -p and get the linking information for the main file in both the static and shared library cases. The script should save the result in static.txt and dynamic.txt. Use the diff command in the script to compare these to txt files. Can you interpret the differences (You probably need to review the slides or textbook!).

Green Marinee theme adapted by David Gilbert, powered by PmWiki