Search code examples
cgccubuntu-16.04dynamic-linkingdebian-stretch

C: How to link with different library versions at the same time


I produce a dynamic library (libfoo.so) requires libcrypto.so. Which works fine in the build platform (I build it in Ubuntu 16.04). However when I move the same library to Debian Stretch 9.3, it start to complaining missing libcrypto.so.1.0.0. The openssl package is install in Debian Stretch, but the libcrypto.so is named as libcrypto.so.1.0.2. After a bit of digging, I found out that although the libcrypto.so on Ubuntu 16.04 is named as libcrypto.so.1.0.0 (its SONAME also libcrypto.so.1.0.0), it is actually version 1.0.2.

Here is the question: I do not want to recompiled a special version for Debian, is there anyway that my library can be use on both Linux distributions? Either link with both .so version at the same time, or other methods?

Forgot to mention that, I used gcc compiler, my library is written in C.


Solution

  • In my opinion(Although I haven't done this before)... if your not too worried about the size of your shared object libfoo.so, ... I think your best bet here is going to be to statically link libcrypto.a ( the static version of libcrypto for the version you choose)

    Although I suspect you might run into other c libraries not playing well between the different distributions ( Debian and Ubuntu ) ... even if you were to get it to work maintance would be a nightmare

    (Stuff below might be irrelevant if you are loading your .so object at runtime into a program compiled on the other machine)

    Even if you were to fully statically link the binary... It probably wont work

    https://unix.stackexchange.com/questions/227910/will-my-linux-binary-work-on-all-distros

    For anything that is more complex than a statically linked hello world, the answer is probably no. Without testing it on distribution X, assume the answer is no for X.