injoy
injoy

Reputation: 4373

How to control shared library version issue on Linux?

For example, I create a shared library named libXXX.so.0.0.0 with the soname as libXXX.so.0. So, do I need to create a symlink named libXXX.so.0 and let it points to the real shared library? Or do I just need to create a symlink named libXXX.so?

Besides, what if I update the library to libXXX.so.0.0.1?

  1. If I install the shared library on the system library path, such /lib or /usr/lib, how to update the symlink? Using ldconfig?

  2. If I install the shared library on current local folder, how to update the symlink?

BTW, how control the version issue in Makefile? I mean do I need to add some command such as ln -s or ldconfig?

Upvotes: 5

Views: 3634

Answers (1)

ottomeister
ottomeister

Reputation: 5808

Yes, create a symlink named libXXX.so.0 pointing to libXXX.so.0.0.0.

If you want people to be able to construct programs that are linked against this library then also create a symlink named libXXX.so pointing to libXXX.so.0.

The libXXX.so.0 symlink will be used by the program loader, because that's the soname that the program will be looking for.

The libXXX.so symlink will be used by the linker when it is building a program, because by historical convention that's how the linker works.

Besides, what if I update the library to libXXX.so.0.0.1?

Then you remake the libXXX.so.0 symlink so that it points to libXXX.so.0.0.1. Nothing else needs to change. Since the libXXX.so symlink points to libXXX.so.0 it will automatically also point to the new library.

how to update the symlink?

If you're installing the new library by using some packaging system (RPM, ...) then use whatever feature the packaging system provides for managing symlinks. If you're just using a script or a Makefile stanza then simply rm -f the old symlink and ln -s the new one.

Upvotes: 3

Related Questions