Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the common way to manage shared libraries on Linux?

For example, I need to generate a shared library, libXXX.so.

  1. What's the common way to generate it? Only use -fPIC -shared ?

  2. Do I need to create a soft link to this library? I mean using ln -s.

  3. What if I update the shared libray, ie. from libXXX.so.1.2.3 to libXXX.so.1.2.4, how my project knows that the shared library is updated? Do I need to re-compile the whole project again?

  4. What's the common way to manage the shared library in Makefile?

I totally do not understand these issues. Please do me a favor :-)

like image 905
injoy Avatar asked May 30 '12 08:05

injoy


1 Answers

The topic on which you have raised the question is vast. Most of your questions depend upon your environment and also whether or not to create a softlink depends on in which folder you keep your library and which processes may need to access it etc.

Please check this link & this link also which gives a detailed explanation on creating and using shared libraries.

Some short answers to your questions:

What's the common way to generate it? Only use -fPIC -shared ?

The options used depends on the compiler. fPIC helps in generating position independent code and shared makes the library a shared library. But, apart from, there are also options which can expose only those symbols which you decide to export from your library and options which create a strong link between the global symbols of your library (-symbolic) etc.

Do I need to create a soft link to this library? I mean using ln -s.

As I mentioned above, this depends on where you decide to place your library. The common mechanism is keep your library in some folder of your choice and create a link to it in commonly "known" or accessible folder like /usr/lib etc.

What if I update the shared libray, ie. from libXXX.so.1.2.3 to libXXX.so.1.2.4, how my project knows that the shared library is updated? Do I need to re-compile the whole project again?

One of the main advantages of shared library is that you can update latest versions without having to recompile the entire code. Again achieving this depends on the platform & compiler.

What's the common way to manage the shared library in Makefile?

There are umpteen links available in google and my link also provides some basic detail.

like image 130
Jay Avatar answered Sep 19 '22 18:09

Jay