How can I force the gcc linker to link against a given version (soname) of a shared library on the system?
I need this to enforce that the version of openssl that is #include
'ed matches the version that is linked, on any system, even if multiple versions of openssl are installed. To find the ABI version, my configure script first compiles and runs a program that extracts the SONAME from the headers:
#include <openssl/opensslv.h>
#include <stdio.h>
int main () {
printf(SHLIB_VERSION_NUMBER);
return 0;
}
The SHLIB_VERSION_NUMBER
contains the so
version string, e.g. 0.9.8
or 1.0.2k
or 1.1.0
. But how do I tell gcc
to link against this version of libssl
or libcrypto
rather than just any -lssl
?
I tried "in situ" linking, so that instead of linking with gcc main.c -lcrypto
we use:
gcc main.c libcrypto.so.1.1.0
However it seems the linker libcrypto.so.1.1.0
cannot be found:
gcc: error: libcrypto.so.1.1.0: No such file or directory
I guess the system only searches in the standard locations when using the -l
flag. Is there a better way to make my software link against libcrypto.so.1.1.0
?