After installation of Opencv 2.4.9, I found it created many symbolic links in /usr/local/lib. Say, for libopencv_core.so.2.4.9, when I use
ls -l, it showed
libopencv_core.so -> libopencv_core.so.2.4
libopencv_core.so.2.4 -> libopencv_core.so.2.4.9
My question is, since it already put the real shared library libopencv_core.so.2.4.9 in /usr/lcoal/lib, why bother to create a symbolic link to it, and even another symbolic link to that symbolic link?
Is it better to put real shared libraries in some other place and make symbolic links to them in /usr/local/lib?
Best How To :
The second libopencv_core.so.2.4 ( alias "soname" ) and third libopencv_core.so.2.4.9 ( alias "real name" ) files are the ones that allows you to update libraries ( in this case OpenCV ) and still support programs that want to use older versions of those libraries.
$ ldd a.out
libopencv_core.so.2.4 => /path/to/lib/libopencv_core.so.2.4
ldd, you can see that executable isn't linked to "real name" library ? Reason: For handling library upgrades. Consider two scenarios.
- Library upgrades with backward compatibility => the installer( or
ldconfig ) could update the existing "soname" link ( e.g. libopencv_core.so.2.4 ) to point to newer "real name" library ( e.g. libopencv_core.so.2.4.10 ) and our older executable's will now load the upgraded library.
- Library upgrades without backward compatibility => the installer will create new "soname" link ( for e.g libopencv_core.so.3.0 ) to point to new "realname" library ( for e.g libopencv_world.so.3.0.0 ). Programs built here after, could link to the newer library whereas older programs will continue to load the library pointed by older soname ( libopencv_core.so.2.4 ).
About, the first symbolic link libopencv_core.so ( alias "linker name" ) is only for the linker. For flags like
-lopencv_core, gcc prefixes a
lib and postfixes a
.so to the library name and searches. So it expects a file with name libopencv_core.so and so the need for first symbolic link. It is never used during program runtime. Also, if are willing to the give "soname" link as a gcc command line parameter instead of
-lopencv_core, you will never need this soft link.
Better explained here(1).