How Libraries Work in Programming Part 1

This is article is targeted towards people new to computer science like me. Therefore, you can be sure that everything I will be sharing will be pretty straight forward.

Simply, libraries are files just like your normal application files, just that they are not executable. This means you cannot run them like your normal program. So why do we need libraries in programming?

First, if you are planning to be a C or C++ programmer, you need to learn how libraries work, but if otherwise, you can do without learning the concept. I think it is just cool to know as many concepts as possible to be a good programmer.

As you are reading this article, I am certain you are running your Chrome browser. Maybe you are running some other social media apps on your phone. You see all these programs have many things in common, and I am certain that you will agree that it would be a waste of time and space to keep repeating what they have in common anytime we try to run these applications.

Hope I have not lost you? Here is a simple example: A kind of function (i.e. a program) ensures things are printed on your screen when using chrome, whatsapp, Instagram, YouTube, etc. Imagine the developers on each of these applications have to code a separate function to print on screen, it wouldn’t be the best use of their time.

However, a solution would be to have such function or program that enables stuff to print to be in a separate file and when these application needs it, they can make reference to it.

This has two major advantage:

1.It saves developer the stress of always coding standard functions (thousands of them). 2.It reduces the space your application takes in memory (Not totally true).

If you check your PC, you will see many Libraries. They have different extensions based on the operating system you use. If you tamper with these files, your system might never be able to run some programs again. And in the worst case, if it is a library your OS depends on, your PC is practically gone. I use a window OS, and the image below contains some of the libraries on my PC.

dil files.PNG

The second image is a warning showing the consequence of tampering with the libraries

dilfiles err.PNG

**There are basically two types of Libraries:

1.Shared Library:** Windows Extension: .DLL MacOS Extension: .DYLIB Linux Extension: .SO

2.Static Library: Linux/MacOS Extension: .a Windows Extension: .LIB

Static and Shared/Dynamic libraries pretty much do the same thing, but in different ways. Next time, we would take a deep dive in to that.