For example, I need to generate a shared library, libXXX.so.
What's the common way to generate it? Only use -fPIC -shared ?
Do I need to create a soft link to this library? I mean using ln -s.
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?
What's the common way to manage the shared library in Makefile?
I totally do not understand these issues. Please do me a favor :-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With