Obligar a ld a vincularse a un archivo .so no versionado

Puedo forzar ld to link against an unversioned .so file?

Under linux, when I link a C++ program to a shared library, it will be bound to the versioned .so file, which is normally a very good idea. For example, if I compile my program with

g++ main.cxx -l somelib

y luego verificar

ldd ./a.out

it will print something like

libsomelib.so.1 => /xxxx/somelib/libsomelib.so.1

Because of a system broken elsewhere, this file is installed in a target as libsomelib.so instead of, as normal, as libsomelib.so.1 with symlink. It is not possible for me to change this, so as a workaround I would like to change my makefile to link against the unversioned .so file. (Binary compatibility is not a problem here, since everything is in a controlled environment).

preguntado el 31 de julio de 12 a las 13:07

can't you make a symlink from libsomelib.so to libsomelib.so.1 on the target system? this simlink can reside under the application directory (set LD_LIBRARY_PATH before launching). -

I can probably hack the LD_LIBRARY_PATH, but it will be quite complicated, but I was hoping there was some ld magic I could do to rewrite the dependency... -

1 Respuestas

From reading the ld manual, this does not appear to be possible. I recommend using patchelf to fix it up after the fact, e.g., patchelf --replace-needed libsomelib.so.1 libsomelib.so a.out. Note that the latest released version of patchelf 0.9 is buggy, you will need to compile patchelf master from source to get a working implementation of --replace-needed.

Respondido 05 ago 19, 15:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.