1

I have some very special needs: Is is possible to link a .so file statically to a built executable so that the executable doesn't link this .so dynamically any more?

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
Bonita Montero
  • 2,817
  • 9
  • 22

1 Answers1

-1

An ELF shared object should be somehow dynamically linked and should practically contain position-independent code (this is strongly recommended, but in theory not mandatory). See also this

For all the details, read Drepper's paper How To Write Shared Libraries (more than 100 pages).

Read also the Program Library HOWTO and the C++ dlopen minihowto.

Perhaps you simply want to have the executable be able to do something sensible if the shared library is missing. Then you might simply load it explicitly (as a plugin) at runtime using dlopen(3), handle nicely the failure error case, and on success get the appropriate symbols from it using dlsym(3). See also ld-linux.so(8), elf(5), execve(2), mmap(2)

Perhaps you want to have an entirely static ELF executable. Then you should build it as such (and use static libraries only).

Maybe you want to extract the text, data, and relocation info from the shared object (that might be painfully doable using objdump, readelf, or some code using libbfd or libelf) and rebuild some linkable object file (perhaps with ld -r or some painful ld script). I am not sure it is entirely doable in all cases (e.g. when the .so has dynamic dependencies itself), and it is certainly painful.

PS. Please motivate your question a lot more and explain why you are really asking. I made some blind guesses. I suppose you have access to source code and are able to change some of it.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547