Create a Static Library

Learn how to create a static library in C.

In this and the next lesson, we demonstrate how to create and use a statically linked library. For this, we would create the library and the client that uses the library. First, we would create the library.

Creating a static library in Linux

Follow the steps shown below to create the library:

  1. In lib_static.c, define the factorial( ) function.

  2. Once the header and the source file are created, press the RUN button; it will open the terminal for you, and, then, you can execute the following commands in the given terminal:

  • gcc -c lib_static.c -o lib_static.o

  • ar rcs libstatic.a lib_static.o

Get hands-on with 1200+ tech skills courses.