C STATIC LIBRARIES

Good afternoon in this blog I am going to talk about static libraries in c, what they are, what they are for, how to create and use them.

Static libraries, also known as object-libraries, are collections of object-files within a single file, generally with a .lib or .a extension.
They are always accompanied by header files, generally .h, which contain the declarations of the objects defined in the library. Then, during the linking phase, the linker includes in the executable the modules corresponding to the functions and library classes that have been used in the application. As a result, such modules become part of the executable, in exactly the same way as any other function or class that would have been written in the body of the application.

  • Structure and organization of the default code
  • Code reuse
  • Agility and speed in development.
  • Lower cost in development.
  • Good development practices with the use of patterns.
  • Minimize errors and easier to solve them.
  • Ease of finding a library or code that already covers features of your development.
  • Facilitates collaboration with other developers.
  • Facilitates maintenance.

To create a library we must write this “ar rc (here the name of a library. a ) (here all files with extension .o separated by a space each )“

For example:

ar rc test.a file1.o file2.o

Option ‘c’ tells ar to create the library if it doesn’t already exist.

The ‘r’ option tells you to replace the older object files in the library with the newer object files.

Then in order to use our library the only thing we have to do is, in the header of our program include our library as we usually do #include (name of library) and voila, we can use any function that we have pre-created in our library.

--

--

--

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

Recommended from Medium

Ten Tips for Effective Rebar Detailing in Revit

How to let your AI See!

Flutter: ListView Pagination (Load More) example

5 Lessons From My First 5 Months as a Software Engineer At Yelp

Binary Tree Maximum Path Sum🧭

Introducing: Custom Character Profiles!

Button Loader in Xamarin Forms

SqlDBM Joins Snowflake Partner Connect

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
Facundo Diaz

Facundo Diaz

XD

More from Medium

Branches in Git Bash

Debugging Impossible Bugs: Try Making It Worse

5 Essential Java Skills That Can Help You With Rust Programming?

Stand out as a Java Developer with these tips!