How to get the static libraries available in an android .so file - shared-libraries

I have an android .so(example.so) file which is build with some n number of static libraries(.a files). Is there is any way to find what are the static libraries used to built that .so(example.so) file.

It's not possible to figure out which static libraries were used to build the shared library. Shared libraries aren't a container of their components like static libraries are, but are a linked form of all the object files.
I think the best you can do here is figure out which source files are included, and only if the library hasn't been stripped. You can use readelf -sW libfoo.so, and if it was built from foo.cpp you'll see:
...
18: 00000000 0 FILE LOCAL DEFAULT ABS foo.cpp
...

Related

How generate static library (.a) from shared for dynamic linking

I have a shared library librun.so without source code, but have an SDK to work with it.
How generate static library (librun.a) with only export functions from librun.so for dynamic linking my library libapp.so with librun.so?
On windows it's done like this, but on Linux how?
dumpbin /exports run.dll
Make run.def with export functions
lib /def:run.def /out:run.lib /machine:x86
On Linux you normally don't need explicit static library and just link against shared library directly:
$ gcc ... -o libapp.so -Lpath/to/librun.so -lrun
If you really need an static library, you can generate it via Implib.so:
# Generate wrappers
$ implib-gen.py librun.so
Generating librun.so.tramp.S...
Generating librun.so.init.c...
# Create static library
$ gcc -c -fPIC librun.so.tramp.S librun.so.init.c
$ ar rcs librun.a librun.so.*.o
Note that resulting static library librun.a will be a wrapper which internally loads original librun.so and forwards calls to it (this is same as Windows).

How to link using an external pdb?

In VS2012, I'm statically linking with a precompiled .lib, and need to also use that lib's .pdb file for debugging.
How can I tell the linker that it should use that external pdb file?
If you created the static lib with /ZI or /Zi (see project settings for C/C++ -> General -> Debug Information Format), then the $(IntDir)vc$(PlatformToolsetVersion).pdb file is created. The path is defined by /Fd.
A linker that uses the static library usually also refers to this pdb file. If you link an executable with the static lib and the linker can't find the pdb file you should get the error like this
LNK4099: PDB 'vc1xx.pdb' was not found with 'foo.lib(foo.obj)
So what you want is the default. You may turn on verbose linking to see what happens to your symbols.
Microsoft always ships a PDB file with their static libraries named the same way like the static lib. So you find a libcmt.lib and a libcmt.pdb

linux - make .a corresponding to .so

I have some legacy 'so' file, with the corresponding header, how to make 'a' file out of it
to link with the project ?
(or could I link to 'so' - adding -L/path_to_so/ and -lsomething (assuming so is in /path_to_so and is named libsomething.so does not seem to work - ld complains about missing exports - but they are present in lib (lib is 32bit, -m32 is used, project is 32bit) ?)
I'm not a linux guru, on windows when i have dll and header I'm able to generate lib, that I'm linking with project to use dll - I assume that same is on linux right ?
I have some legacy 'so' file, with the corresponding header, how to make 'a' file out of it to link with the project ?
There is no way to make .a. from .so. On Linux .so get linked directly, no import library is required.

gcc --whole-archive --no-whole-archive: Dynamic Library Integrity

When using the -Wl--whole-archive ... -Wl--no-whole-archive flags with gcc how is it that you veryify that everything links correctlly internal to the library? Also how do you verify that the library can call into other Dynamic libries that are specifed by LD_LIBRARY_PATH or ld(1)?
Assuming you want to build a shared library one solution would be to link a minimal executable against that library as part of you build and see if you get unresolved symbols. Of course this file wouldn't be installed.
The executable you build can really be minimal, for my C++ code I usually use
int main() { }

Autoconf, Libtool shared and static library

I am using autoconf gnu tools to build my product.
It generates both the shared as well as static library for any library where *.la is mentioned.
The issue is if you use .la to link your binary in Makefile.am.
It links with the dynamic library but when you use ldd to the binary, it says
"not a dynamic executable" although it links with shared library. I proved it by removing the shared library after the binary is built and then tried to run the binary. It didn't find the shared library and couldn't run.
Another question is how to put library in a specified location using Makefile.am direction ?
Looks like you run ldd on the wrapper scripts created by libtool. They are used to link uninstalled libraries with uninstalled executables. Real binaries are placed in .libs directory.
You can install a lib to some specific place in this way
mylibrary_LTLIBRARIES = libmylibrary.la
mylibrarydir = ${libdir}/my_plugins/

Resources