0

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?

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
BusyTraveller
  • 183
  • 3
  • 14
  • 1
  • Related (and possibly duplicates): [How to make rpm auto install dependencies](https://stackoverflow.com/q/13876875/608639), [Automatically install build dependencies prior to building an RPM package](https://stackoverflow.com/q/13227162/608639), [Failing an RPM install programmatically in a spec step](https://stackoverflow.com/q/4037410/608639), [Check RPM dependencies](https://stackoverflow.com/q/19077538/608639), etc. – jww Jun 06 '17 at 07:11

2 Answers2

4

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;)

  • He probably needs to script it in the `%pre%` or `%install%` section like in [Failing an RPM install programmatically in a spec step](https://stackoverflow.com/q/4037410/608639) – jww Jun 06 '17 at 07:15
  • @el.pescado..in that case, I have to check for the "not found" string for failed dependencies.Actually ....ldd in turn will be using some logic to find out the dependencies. Any idea regarding that ? I think I have to analyse the source code of ldd. – BusyTraveller Jun 06 '17 at 07:29
  • `ldd` is a shell script which uses `ld-linux` (which may be instaled in different places, e.g. `/lib64/ld-linux-x86-64.so.2`) with `--verify` flag. – el.pescado - нет войне Jun 06 '17 at 08:10
  • @el.pescado..this program needs to be installed in thousands of user PCs, where the users are not having in depth knowledge of linux.They are expecting a click-click installation like in windows.So, the installation script should find the missing dependencies and install those dependencies in the background.That is why I am trying for automation.If there is no other way, I have to go with rpm or debian based installations.I would be quite useful if I can know how rpm and debian based installations are finding the dependencies. – BusyTraveller Jun 06 '17 at 08:47
0

RPM will automatically detect used libraries and put needed Requires into final RPM package. You can check it using:

rpm -qpR foo.rpm

and it should print something like:

libc.so.6(GLIBC_2.8)(64bit)
libdl.so.2()(64bit)
msuchy
  • 5,162
  • 1
  • 14
  • 26