I have some scenario like this:
Product-> Platform-> mylibs(version-1)
Product-> mylibs(version-2)
i.e Product uses mylibs (version-2) directly. Product also uses platform (which is also a dynamic lib) and platform uses my libs (version-1).
The names of the libs used by product and platform are same. Only versions are different and both these versions are not compatible.
Is there a way with ".so" libs in linux that Platform can link to one version and product can link to another version of the same libs having the same name?
Note, even changing the names of the libs won't be enough by default, as symbol names would conflict. Your libs should use soname and versioned symbols, in which case they can even be called the same.
$ make
gcc -shared -fpic -Wl,-soname -Wl,libmylibs.so.1 -Wl,--default-symver -o libmylibs.so.1 mylibs1.c
gcc -shared -fpic -Wl,-soname -Wl,libmylibs.so.2 -Wl,--default-symver -o libmylibs.so.2 mylibs2.c
gcc -shared -fpic -Wl,-soname -Wl,libplatform.so.1 -Wl,--default-symver -Wl,--default-imported-symver -o libplatform.so.1 platform.c libmylibs.so.1
gcc -Wl,-rpath-link -Wl,. -Wl,--default-imported-symver -o program program.c libplatform.so.1 libmylibs.so.2
/usr/bin/ld: warning: libmylibs.so.1, needed by libplatform.so.1, may conflict with libmylibs.so.2
$ LD_LIBRARY_PATH=$PWD ldd ./program
linux-vdso.so.1 => (0x00007fff1e3ff000)
libplatform.so.1 => /tmp/so-4539442/libplatform.so.1 (0x00007f6dc3ba0000)
libmylibs.so.2 => /tmp/so-4539442/libmylibs.so.2 (0x00007f6dc399f000)
libc.so.6 => /lib/libc.so.6 (0x00007f6dc364c000)
libmylibs.so.1 => /tmp/so-4539442/libmylibs.so.1 (0x00007f6dc344b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6dc3da1000)
$ LD_LIBRARY_PATH=$PWD ./program
lib version 2, platform lib version 1
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