|
Exercises: code compilation and the libraries
Single code compilation.
By following the instructions below, download and compile a C code,
single.c,
that computes the scalar product of two vectors:
When prompted for the input parameters, type in the dimension of the vectors
and the value of their components, for example:
Compile the code with a static library.
This time, the original single.c file has been devided into 3 separate modules: main.c, Scalar_Product.h, and Scalar_Product.c.
Download the archive and untar it into a new directory:
Build the static library:
Verify the content of library libScalar_Product.a:
Compile the main code and link with the library:
Make sure the compiled code runs fine:
Compile the code with a shared library.
Create a new directory and untar the source code in it:
Build the shared library:
Compile the main code and link with the shared library:
Verify that app.x executable requires libScalar_Product.so
library:
It should show that the shared library is not found, libScalar_Product.so => not found.
Try running the code
It should fail to run.
Set LD_LIBRARY_PATH environment variable to include the current working
directory:
Check if the loader finds the library and try running the code again:
|
|