I’m compiling some code which uses libcurl on a Debian Linux system. My dev machine is running Debian 5 but I want the binary to be usable on older Debian 4 systems too.
I find that if I specify -lcurl it will link to libcurl.so.4 but Debian 4 systems only have libcurl.so.3
Is there some way I can tell GCC to link to either libcurl.so.3 (which exists in both Debian 4 and 5) or just libcurl.so so it will use whatever version is available ?
You can pass the specific version shared library file using the syntax
-l:libfoo.so.1that specifies the filename instead of the syntax-lfoothat specifies the library name following the conventionlibfoo.soon the linker command line, and it ought to do what you want as can be seen at the linker documentation section for the option--library=namespec.In order to provide more details on how to link to a specific version through an example, consider a system that contains two versions of the same library, namely
libfoo.so.1.0andlibfoo.so.2.0installed in one of the library directories, in this case/lib.A program compiled with the option
-lfoowill make the linker look for a file that relies on the naming convention and thus resolve to/lib/libfoo.so(for a shared library object) or/lib/libfoo.a(for a static library object).In contrast to that, a program compiled with the option
-l:libfoo.so.1will be linked against/lib/libfoo.so.1, that is a itself currently a symbolic link tolibfoo.so.1.1as can be seen from the listing above, a minor update from 1.0.And finally, a program compiled with the option
-l:libfoo.so.2will be linked against/lib/libfoo.so.2, that is itself currently a symbolic link tolibfoo.so.2.2as can be seen from the listing above, a minor update from 2.0 and 2.1.Should you install a newer version of such library, as long as it is a minor update, there should be no need to recompile programs linked to it, since compatible versions should have the same soname and the symbolic links should be updated accordingly.