Linux libraries 101 and distributing them with your app
ldd
First tool to master the use of is ldd
You use ldd to view the current library requirement list and where they are found it the current system.
[dev@squarepants stage]$ ldd tsmuxer linux-gate.so.1 => (0x00426000) libavfilter.so.6 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libavfilter.so.6 (0x00177000) libavformat.so.57 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libavformat.so.57 (0x0042b000) libavcodec.so.57 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libavcodec.so.57 (0xf61b0000) libswscale.so.4 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libswscale.so.4 (0x00b93000) libswresample.so.2 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libswresample.so.2 (0x00a29000) libavutil.so.55 => /home/dev/builds/tsmuxer/ort/stage/ffmpeg/lib/libavutil.so.55 (0x0034a000) libpthread.so.0 => /lib/libpthread.so.0 (0x00b39000) libudev.so.0 => /lib/libudev.so.0 (0x00866000) libdl.so.2 => /lib/libdl.so.2 (0x00b32000) librt.so.1 => /lib/librt.so.1 (0x00b56000) libX11.so.6 => /usr/lib/libX11.so.6 (0x00670000) libXv.so.1 => /usr/lib/libXv.so.1 (0x00967000) libXext.so.6 => /usr/lib/libXext.so.6 (0x003c0000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00876000) libm.so.6 => /lib/libm.so.6 (0x003d2000) libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00e55000) libc.so.6 => /lib/libc.so.6 (0x00c1e000) /lib/ld-linux.so.2 (0x00977000) libxcb.so.1 => /usr/lib/libxcb.so.1 (0x003fc000) libXau.so.6 => /usr/lib/libXau.so.6 (0x00427000)
It is also useful when libraries are missing, it will tell you which.
Let say after deployment on the customer system you have this error.
output:./tsmuxer: error while loading shared libraries: libavfilter.so.6: wrong ELF class: ELFCLASS64
Then use ldd to check what is going on
[root@localhost ~]# ldd tsmuxer linux-gate.so.1 => (0x002a7000) libavfilter.so.6 => not found libavformat.so.57 => not found libavcodec.so.57 => not found libswscale.so.4 => not found libswresample.so.2 => not found libavutil.so.55 => not found libpthread.so.0 => /root/./../lib/libpthread.so.0 (0x0024d000) libudev.so.0 => not found libdl.so.2 => /root/./../lib/libdl.so.2 (0x0085b000) librt.so.1 => /root/./../lib/librt.so.1 (0x00fef000) libX11.so.6 => /usr/lib/libX11.so.6 (0x00e39000) libXv.so.1 => /usr/lib/libXv.so.1 (0x00120000) libXext.so.6 => /usr/lib/libXext.so.6 (0x00125000) libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00137000) libm.so.6 => /root/./../lib/libm.so.6 (0x009d3000) libgcc_s.so.1 => /root/./../lib/libgcc_s.so.1 (0x007ae000) libc.so.6 => /root/./../lib/libc.so.6 (0x002a8000) /lib/ld-linux.so.2 (0x00b89000) libxcb.so.1 => /usr/lib/libxcb.so.1 (0x00222000) libXau.so.6 => /usr/lib/libXau.so.6 (0x004e2000)
Fixing library issues with patchelf
patchelf --set-rpath '$ORIGIN/lib' <application-binary>
What patchref does is edit the path that tells where to look for the libraries. It edits the binary directly. So you do this once, then redistribute that binary and the lib folder.
In my case I excecuted
./patchelf --set-rpath '$ORIGIN/tsmuxer-lib' tsmuxer
Recent Comments