Let say I have libA.so and libB.so, is there any way for me to combine them into a single shared library libC.so that contains all exported symbols of both libA.so and libB.so?

  • I assume that you do not have the source code of these libraries (just to make things clear!). But, have you access to a static version (*.a) of it ?
    – perror
    Dec 26, 2013 at 14:05
  • No, I have neither source code nor static version.
    – Krypton
    Dec 27, 2013 at 1:16

1 Answer 1


Quite frankly this is rather a development (i.e. StackOverflow) question than RCE, but let me give the level of advice I can give with the level of information you provided in your question.

The question is whether what you want to achieve is to have those symbols available through a single library by all means or whether you don't care how both sets of symbols are made available to your program(s).

If you insist on the library, you could simply write one shared library and export the symbols from it through shallow wrapper functions, but use the dynamic loader to find them from the originating shared objects (check out ldd and related man pages). It is not too difficult to find all symbol names with readelf --dyn-syms <elf-file>/readelf --syms --use-dynamic <elf-file> (the package on Ubuntu/Debian is elfutils). From the output of that you can write a version script to use in your linker (e.g. gcc -Wl,--version-script,script.map ...).

However, assuming you use the default Linux facilities with no additional magic involved, you can also abuse the ld-linux/ld.so approach of locating the symbols. If you write a simple wrapper shell script that sets LD_PRELOAD, you can simply load both shared objects up front and they should - under normal circumstances - take precedence over other symbols. It's also commonly used as a debugging technique.

I strongly suggest you read chapters 41 and 42 of Michael Kerrisks excellent book "The Definitive Guide to Linux and Unix System Programming", colloquially known as TLPI. The respective source samples may come in handy, too, in your case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.