How to find library type (.so or .a) in C ++ / UNIX

Given a C ++ / UNIX library file (no extension), I need to determine the type of library, be it a dynamic library (.so file) or a static library (.a file) based on its content (say grepping content against a keyword)

How do I do this on the UNIX command line?

+2


source to share


2 answers


Try file <library name>

. It should display shared

or dynamically linked

among its output if the file is a dynamically loadable module.



+5


source


Try file -L <library name> | grep shared

if this produces any output, the file is dynamically linked. Alternatively, you can do ldd <library name> | grep 'not a dynamic executable'

that which produces the output if it is static. Hopefully this answers your question, I would add a comment to Aviator, but I cannot comment (yet).

Option -L

to force file downloads to unbind symbolic links, which is not the default behavior if POSIXLY_CORRECT is not defined (as is the case on my system).



Script example:

if [-z "$ (file -L | grep shared)"]; then
    echo "not a dynamic lib";
else
    echo "dynamic lib";
+1


source







All Articles