Static libraries in C language

  • Get the object files (.o) from all our sources (.c). For this they are compiled with cc -c source.c -o source.o. The -c option tells the compiler not to create an executable, but just an object file. Here I put the cc compiler, because it is the one I used for the example, but you can use GCC, or the g ++ (for C ++) or one of Fortran, Pascal, etc.
  • Create the library (.a). To do this, the ar command is used with the following parameters: ar -rv libname.a source1.o source2.o … The -r option tells the ar command that it has to insert (or replace if they are already inside) the files object in the library. The -v option is “verbose”, so it displays information while you’re doing things. Next, we put all the object files that we want. ar is actually a much more generic command than all this and can be used to pack any type of file (not just object files). It also has options to see what files are inside, delete some of them, replace them, etc.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Using Interceptor in a Spring Boot API

From Enthusiasm to Accomplishment-Speedy delivery of iOS 14 Widget

Revision Guide for MB-200: Microsoft Power Platform + Dynamics 365 Core

Puzzles in the Terraverse: Chapter 2

CS371p Fall 2021 blog 6: Zein Fakhreddine

DiffUtil — performant one way data flow with RxJava and Kotlin

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Paola Andrea Garcia Altamirano

Paola Andrea Garcia Altamirano

More from Medium


C Static Libraries and gcc

C static libraries

Errors in Jurassic Park