Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you link to a specific version of a shared library in GCC

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 ?

like image 972
Adam Pierce Avatar asked May 06 '09 04:05

Adam Pierce


People also ask

Which option of GCC compiler provides the linking with shared libraries?

6. Which option of GCC compiler provides the linking with shared libraries? Explanation: None.

How are shared libraries linked?

Shared libraries (also called dynamic libraries) are linked into the program in two stages. First, during compile time, the linker verifies that all the symbols (again, functions, variables and the like) required by the program, are either linked into the program, or in one of its shared libraries.

How do I link a shared library in Makefile?

As already mentioned here, the thing you probably want is the linker option -rpath . Like that, you can set a default search path for the binary. Looks like you even already use -rpath in your makefile, but you specify the wrong path: LIBS = -L$(LIB) -lfuse -lsqlite3 -lkw_taglib -ltag_c -ltag -Wl,-rpath=.

How do I open a shared library file?

If you want to open a shared-library file, you would open it like any other binary file -- with a hex-editor (also called a binary-editor). There are several hex-editors in the standard repositories such as GHex (https://packages.ubuntu.com/xenial/ghex) or Bless (https://packages.ubuntu.com/xenial/bless).


2 Answers

Instead of using "-lcurl" use "-l:libcurl.so.3" And ofcourse also use "-L _installed_path_"

like image 134
engineer.udays Avatar answered Sep 19 '22 11:09

engineer.udays


You can pass the actual .so file instead of -l on the linker command line, and it ought to do what you want.

like image 41
bdonlan Avatar answered Sep 21 '22 11:09

bdonlan