Skip to content
Advertisement

How to programmatically check whether a library dependent program can run in a Linux system?

I am having a program(binary) which depends upon libraries such as pthread, sqlite3,libcrypto and libcurl.I want to run this program in multiple user PCs.How to programmatically check whether the dependencies are met, before installing the binary?

./configure cannot be be used as it is for the purpose of building the program as mentioned in , Making os independent configure file which checks for curl dependency. If I am not wrong .deb and .rpm have there own methods for this.

Can anybody please tell me what is the method they are following for this.Is it just a file name check? For example,if I have build the program using libcurl.so.3, whether it checks that the system in which it will be running is having libcurl.so.3 as a regular file or a simulink.Or any other check is there for the libraries?

What is the reliable method for checking the dependencies, while installing and running a binary?

Advertisement

Answer

Building a package

You could distribute your program as .deb or .rpm package. Both formats support specifying dependencies that need to be present:

Checking manually using ldd

You could use ldd(1) to check whether necessary shared libraries are installed and how they are resolved:

$ ldd /usr/bin/xterm
        linux-vdso.so.1 =>  (0x00007fff649ff000)
        libXft.so.2 => /usr/lib/x86_64-linux-gnu/libXft.so.2 (0x00007fc5195cd000)
        libXaw.so.7 => /usr/lib/x86_64-linux-gnu/libXaw.so.7 (0x00007fc51935b000)
        libutempter.so.0 => /usr/lib/libutempter.so.0 (0x00007fc519158000)
        libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fc518f2f000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc518ba2000)
        libfontconfig.so.1 => /usr/lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007fc51896a000)
        libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007fc51862f000)
        libXmu.so.6 => /usr/lib/x86_64-linux-gnu/libXmu.so.6 (0x00007fc518415000)
        libXt.so.6 => /usr/lib/x86_64-linux-gnu/libXt.so.6 (0x00007fc5181ad000)
        libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007fc517f92000)
        libfreetype.so.6 => /usr/lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fc517cf3000)
        libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fc517ae9000)
        libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007fc5178d7000)
        libXpm.so.4 => /usr/lib/x86_64-linux-gnu/libXpm.so.4 (0x00007fc5176c6000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fc5197f8000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fc5174ae000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007fc517284000)
        libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fc517064000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fc516e5f000)
        libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007fc516c58000)
        libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007fc516a54000)
        libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fc51684f000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fc51664a000)

When required libraries are not found, “not found” is printed:

$ ldd bar
        linux-vdso.so.1 =>  (0x00007fffde7ff000)
        libfoo.so => not found
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5954eae000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f5955251000)

Unfortunately, ldd does not return useful exit code in that case.

Keep it simple, stupid

You could just try to run your program and when it fails due to missing libraries, then… you know that you are missing some libraries;)

Advertisement