Close

March 23, 2018

Porting Software – Get your RPM’s right.

The other day I was porting some C++ applications from Centos 7 to Fedora 25/27. Of course CMake helps with the compilation part. However, when I was standing up a new VM with Fedora 27, I wanted to quickly ensure I had the right libraries present on the system to check that compilation/linking would succeed.

I hadn’t got the stage of listing required dependencies for the package, otherwise rpm -qpR /path/to/rpm/file.rpm would be useful.

So I would normally execute the following commands on Centos 7 (where my executable was compiled) to see what  RPM’s would need installing on Fedora 27 (where I was porting to).

1. ldd /path/to/executable to reveal the shared libs that are dynamically linked to the executable.

2. For every library path in ldd output, issue rpm -qf /library/path

This gets a bit monotonous after a while!! So I developed ldd2rpm. Basically its a small python program that uses rpm module to interrogate the rpm database.

Now you can do cool things like this.

0:27 $ ./ldd2rpm.py  ../missile_run/build/missile_run 
systemd-libs-219-42.el7_4.10.x86_64
libXrender-0.9.10-1.el7.x86_64
freetype-2.4.11-15.el7.x86_64
libSM-1.2.2-2.el7.x86_64
zlib-1.2.7-17.el7.x86_64
libuuid-2.23.2-43.el7_4.2.x86_64
elfutils-libs-0.168-8.el7.x86_64
libxcb-1.12-1.el7.x86_64
libICE-1.0.9-9.el7.x86_64
libXau-1.0.8-2.1.el7.x86_64
xz-libs-5.2.2-1.el7.x86_64
flac-libs-1.3.0-5.el7_1.x86_64
libgcc-4.8.5-16.el7_4.2.x86_64
libvorbis-1:1.3.3-8.el7.x86_64
elfutils-libelf-0.168-8.el7.x86_64
openal-soft-1.16.0-3.el7.x86_64
libXrandr-1.5.1-2.el7.x86_64
glibc-2.17-196.el7_4.2.x86_64
libX11-1.6.5-1.el7.x86_64
libjpeg-turbo-1.2.90-5.el7.x86_64
libstdc++-4.8.5-16.el7_4.2.x86_64
libXcomposite-0.4.4-4.1.el7.x86_64
libXfixes-5.0.3-1.el7.x86_64
libattr-2.4.46-12.el7.x86_64
libXdamage-1.1.4-4.1.el7.x86_64
libXext-1.3.3-3.el7.x86_64
bzip2-libs-1.0.6-13.el7.x86_64
libogg-2:1.3.0-7.el7.x86_64
libcap-2.22-9.el7.x86_64

This output shows the RPM packages that provide the shared libraries dynamically linked to your executable. Now you have an idea of what RPM’s to install on the target system that you are porting to.

If you want a little more verbosity, add the -v flag to the command line.

0:12 $ ./ldd2rpm.py -v ../missile_run/build/missile_run 
systemd-libs-219-42.el7_4.10.x86_64                   /lib64/libudev.so.1
libXrender-0.9.10-1.el7.x86_64                        /lib64/libXrender.so.1
freetype-2.4.11-15.el7.x86_64                         /lib64/libfreetype.so.6
libSM-1.2.2-2.el7.x86_64                              /lib64/libSM.so.6
zlib-1.2.7-17.el7.x86_64                              /lib64/libz.so.1
libuuid-2.23.2-43.el7_4.2.x86_64                      /lib64/libuuid.so.1
elfutils-libs-0.168-8.el7.x86_64                      /lib64/libdw.so.1
libxcb-1.12-1.el7.x86_64                              /lib64/libxcb.so.1
libICE-1.0.9-9.el7.x86_64                             /lib64/libICE.so.6
libXau-1.0.8-2.1.el7.x86_64                           /lib64/libXau.so.6
xz-libs-5.2.2-1.el7.x86_64                            /lib64/liblzma.so.5
flac-libs-1.3.0-5.el7_1.x86_64                        /lib64/libFLAC.so.8
libgcc-4.8.5-16.el7_4.2.x86_64                        /lib64/libgcc_s.so.1
libvorbis-1:1.3.3-8.el7.x86_64                        /lib64/libvorbisenc.so.2
                                                      /lib64/libvorbisfile.so.3
                                                      /lib64/libvorbis.so.0
elfutils-libelf-0.168-8.el7.x86_64                    /lib64/libelf.so.1
openal-soft-1.16.0-3.el7.x86_64                       /lib64/libopenal.so.1
libXrandr-1.5.1-2.el7.x86_64                          /lib64/libXrandr.so.2
glibc-2.17-196.el7_4.2.x86_64                         /lib64/libm.so.6
                                                      /lib64/libc.so.6
                                                      /lib64/libpthread.so.0
                                                      /lib64/librt.so.1
                                                      /lib64/libdl.so.2
libX11-1.6.5-1.el7.x86_64                             /lib64/libX11.so.6
libjpeg-turbo-1.2.90-5.el7.x86_64                     /lib64/libjpeg.so.62
libstdc++-4.8.5-16.el7_4.2.x86_64                     /lib64/libstdc++.so.6
libXcomposite-0.4.4-4.1.el7.x86_64                    /lib64/libXcomposite.so.1
libXfixes-5.0.3-1.el7.x86_64                          /lib64/libXfixes.so.3
libattr-2.4.46-12.el7.x86_64                          /lib64/libattr.so.1
libXdamage-1.1.4-4.1.el7.x86_64                       /lib64/libXdamage.so.1
libXext-1.3.3-3.el7.x86_64                            /lib64/libXext.so.6
bzip2-libs-1.0.6-13.el7.x86_64                        /lib64/libbz2.so.1
libogg-2:1.3.0-7.el7.x86_64                           /lib64/libogg.so.0
libcap-2.22-9.el7.x86_64                              /lib64/libcap.so.2

The first columns shows the RPM package name that provides the shared library dynamically linked to the executable.
The second column shows the path of the shared library.

This code is available on Bitbucket, along with further description and examples.

Enjoy !!