LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Basic Concept about linking (https://www.linuxquestions.org/questions/linux-newbie-8/basic-concept-about-linking-255735/)

Kreature 11-16-2004 05:55 PM

Basic Concept about linking
 
Just wondering if someone could give me the rundown on linking librarys why we do it what its good for and everything else i should know before i tackle this. I have to download some newer libs so i can install a prog i believe i am going to run into some linking and i would just like to know what i am doing thx.

michaelk 11-16-2004 06:11 PM

When making (compiling) a program, rather than having to rewrite all the functions for dealing with the kernel, hardware, files, etc. every time you write a new program, all these basic functions are instead kept in libraries. glibc, which you install later, is one of these major libraries, which contains code for all the basic functions programs use, like opening files, printing information on the screen, and getting feedback from the user. When the program is compiled, these libraries of code are linked together with the new program, so that it can use any of the functions that the library has.

However, these libraries can be very large (for example, libc.a can often be around 2.5 MB), so you may not want a separate copy of each library attached to the program. Just imagine if you had a simple command like ls with an extra 2.5 MB attached to it! Instead of making the library an actual part of the program, or statically linked, the library is stored as a separate file, which is loaded only when the program needs it. This is what we call dynamically linked, as the library is loaded and unloaded dynamically, as the program needs it.

So now we have a 1 KB file and a 2.5 MB file, but we still haven't saved any space (except maybe RAM until the library is needed). The real advantage of dynamically linked libraries is that we only need one copy of the library. If ls and rm both use the same library, then we don't need two copies of the library, as they can both get the code from the same file. Even when in memory, the two programs share the same code, rather than loading duplicates into memory. So not only are we saving hard disk space, but also precious RAM.

Is this your question?


All times are GMT -5. The time now is 09:31 PM.