20

In C language what is the difference between a static libraray and a dynamic library?

KaramJaber
  • 851
  • 5
  • 13
  • 24
  • Try this [http://stackoverflow.com/questions/20229364/what-is-the-difference-between-a-static-library-and-a-dynamic-one][1] [1]: http://stackoverflow.com/questions/20229364/what-is-the-difference-between-a-static-library-and-a-dynamic-one – Stef Nov 26 '13 at 22:37

2 Answers2

50

This concept might be a little bit too broad to explain, but i will try to give you a basic idea from which you can study further.

Firstly, you need to know what a library is. Basically, a library is a collection of functions. You may have noticed that we are using functions which are not defined in our code, or in that particular file. To have access to them, we include a header file, that contains declarations of those functions. After compile, there is a process called linking, that links those function declarations with their definitions, which are in another file. The result of this is the actual executable file.

Now, the linking as I described it is a static linking. This means that every executable file contains in it every library (collection of functions) that it needs. This is a waste of space, as there are many programs that may need the same functions. In this case, in memory there would be more copies of the same function. Dynamic linking prevents this, by linking at the run-time, not at the compile time. This means that all the functions are in a special memory space and every program can access them, without having multiple copies of them. This reduces the amount of memory required.

As I mentioned at the beginning of my answer, this is a very simplified summary to give you a basic understanding. I strongly suggest you study more on this topic.

Paul92
  • 8,827
  • 1
  • 23
  • 37
2

In windows:

The static library is a .lib file that will be linked inside your executable and won't change with time.

The dynamic library is a .dll file linked to your executable and may change depending on the dll file you load when you execute it.

Dr. Essen
  • 603
  • 2
  • 9
  • 25
fernando.reyes
  • 597
  • 2
  • 15