LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Static vs shared (https://www.linuxquestions.org/questions/linux-newbie-8/static-vs-shared-416159/)

merchtemeagle 02-16-2006 01:47 PM

Static vs shared
 
When you ./configure an application to compile it, in most cases you can choose as options:

--enable-static
--enable-shared

What are the advantages/disadvantages of both options?

Tinkster 02-16-2006 01:55 PM

Mainly size & "portability" ... have a search on the forums, I
gave a spiel on that not too long ago ;)


Cheers,
Tink

atom 02-16-2006 03:30 PM

Static linking of libraries is faster (on startup), and ensures that the application will work even if you don't have the library installed. However, such applications do not share the same instance of the library in memory, and therefore waste precious RAM.

If you share libraries, one library is only loaded into RAM once (therefore giving you a performance boost if you have it loaded already by another program or another instance of the same program), and the library can be upgraded for a binary-compatible version at any time, without the program having to be recompiled, allowing for fixing bugs faster and easier.

The performance penality for loading shared libraries is almost negated by the use of the program called prelink (called prelinking a library), if you're interested, read up on prelink on gentoo howtos, they are a useful theoretical guide for other distros as well, even if they don't use portage...

So, to sum up, a statically-linked program will run anywhere and not suffer from the danger of missing libraries, but will be less efficient and waste RAM.

Conclusion: if you have a system for your own leasure, use dinamic linking (with optional prelink), if you are a developer that uses an obscure and weird library, or are a programmer that isn't sure that QT is installed on a target system, use static linking.



And cheers.


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