What's the difference between static and dynamically linked library...
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What's the difference between static and dynamically linked library...
Libraries have always been ambiguous to me. I would love to have a clear understanding of them.
Here's what I know so far...
Ok I know that libraries are a bunch of functions and definitions in C that binaries use.
I also understand that static libraries are used by the binaries in /sbin:/usr/sbin:/usr/local/sbin
and dynamically linked libraries are used by the binaries in /bin:/usr/bin:/usr/local/bin
So why have statically linked and dynamically linked libraries?
I know that dynamically linked libraries are used to save space. Otherwise each binary would need its own private copy of a library.
So dynamically libraries are used to save space.
Is this understanding correct so far?
Now for my questions...
1. Where are the static libraries and the dynamically linked libraries located in the file structure?
2. Where does ldconfig fit into all of this?
3. Would a rootkit affect both statically and dynamically linked libraries? I would think yes unless the libraries only have read permissions.
4. If the above is true, is there any reason for your libraries to have write permission other than when you want to edit them?
Libraries have always been ambiguous to me. I would love to have a clear understanding of them.
Here's what I know so far...
Ok I know that libraries are a bunch of functions and definitions in C that binaries use.
I also understand that static libraries are used by the binaries in /sbin:/usr/sbin:/usr/local/sbin
and dynamically linked libraries are used by the binaries in /bin:/usr/bin:/usr/local/bin
So why have statically linked and dynamically linked libraries?
Where did that come from? I've never heard this before, nor
can I (using ldd run against any program in sbin) confirm
the theory in actual installations.
Quote:
Originally Posted by trist007
I know that dynamically linked libraries are used to save space. Otherwise each binary would need its own private copy of a library.
So dynamically libraries are used to save space.
Is this understanding correct so far?
That's correct.
Quote:
Originally Posted by trist007
Now for my questions...
1. Where are the static libraries and the dynamically linked libraries located in the file structure?
Just go have a look.
dynamic libraries are called .so. something (commonly
with a version mumble at the end). Static ones are .la
Quote:
Originally Posted by trist007
2. Where does ldconfig fit into all of this?
It let's apps find shared libs easily by caching info.
Quote:
Originally Posted by trist007
4. If the above is true, is there any reason for your libraries to have write permission other than when you want to edit them?
Static libraries are linked at compile time so they are contained in whatever executable (.exe) that uses them. Dynamic libraries are linked at run-time and are contained in their own file (.dll).
So then a rootkit can affect either static/dynamic assuming an attacker gains root and adds write permissions to the dynamic link libraries (*.so) and overwrites them with the rootkit's version of those libraries. As for the static libraries, they are already embedded into the binaries correct? So take the 'w' binary. A rootkit would replace that binary and of course the embedded library in the binary(I understand that the binary has the library built into the binary, since the file itself is nothing but 0s and 1s) so it would only affect that one binary and not all the others. As for the dynamic libraries a rootkit just needs to replace the *.so files with its own libraries and essentially all binaries that use DLL's will be affected. So in a sense static libraries are more resilient. Also, I would think static library binaries run a little faster than DLL binaries. What other significant differences are there between static/dynamic?
1. If static libraries are built into the binary, say the 'hostname' binary, then why would there also be a separate .la file?
2. So ldconfig refreshes the cache so that apps can find their DLL's easily. So I would imagine ldconfig is run at boot? Also, after installing a module or program that uses DLL, it would be necessary to run ldconfig as well no?
1. If static libraries are built into the binary, say the 'hostname' binary, then why would there also be a separate .la file?
So new statically linked programs you may want to
build can be linked against it.
Quote:
Originally Posted by trist007
2. So ldconfig refreshes the cache so that apps can find their DLL's easily. So I would imagine ldconfig is run at boot? Also, after installing a module or program that uses DLL, it would be necessary to run ldconfig as well no?
Depends on your distro & preferences. Most distros these
days will probably kick ldconfig off on boot; I choose not
to, and run ldconfig manually each time I install something
new ... everyones mileage may vary.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.