Static Linking:
Let us consider math.c file. We want to make it as a static library.
First we compile it with position independent flag on(-fPIC). This is needed for dynamic/static linking.
$cc -fPIC -c math.c

Now make a archive or static lib with the object file.
$ar rc libmath.a math.o

To use this static library in a application we need to do the following steps:

  1. compile the application code (place math.h in include folder)
    $cc -c app.c -Iinclude -o app.o
  2. Link with static library math.a
    $ld app.o libmath.a -o app
  3. Run the application
    $./app

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

raise signal, abort exit, Libraries, static linking, dynamic linking methods, implicit dynamic linking, explicit dynamic linking,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan