Linux how to compile binary with static sharedobjects embedded instead of dynamic to use on multi-distributions and avoid glibc compatiblity issues

One simple flag to configure will create a makefile that statically links all the shared objects and embeds them instead the binary execute.  This means as long as you have the same architecture that things should run.

Eg. if you have an old version of Debian with a different version of glibc, then this will solve that problem.

./configure LDFLAGS="-static"

To test that it is really statically linked run ldd:

ldd src/wget
    not a dynamic executable

Whereas the standard dynamic binary will be linked to a bunch of .so shared object files which is obviously a pain if making your own Linux distro or needing portability between distros.

 ldd /usr/bin/wget
    linux-vdso.so.1 =>  (0x00007ffe59ded000)
    libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f8d3b786000)
    libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f8d3b581000)
    libssl.so.1.0.0 => /lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f8d3b319000)
    libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f8d3aed4000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f8d3acba000)
    libidn.so.11 => /usr/lib/x86_64-linux-gnu/libidn.so.11 (0x00007f8d3aa87000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8d3a6bd000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f8d3a4a0000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f8d3bc70000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f8d3a29c000)

 


Tags:

linux, compile, binary, static, sharedobjects, embedded, dynamic, multi, distributions, glibc, compatiblity, issuesone, configure, makefile, statically, links, objects, embeds, execute, architecture, eg, debian, ldflags, quot, linked, ldd, src, wget, executable, whereas, distro, portability, distros, usr, bin, vdso, ffe, ded, libpcre, lib, _, gnu, libuuid, libssl, libcrypto, aed, libz, acba, libidn, aa, libc, bd, libpthread, ld, bc, libdl,

Latest Articles

  • Aruba/HP/Dell IAP Wireless Controller Common Default Passwords
  • Debian, Mint Ubuntu how to remove package and associated config files
  • Linux Grub not booting the intended kernel solution in Debian, Mint, Ubuntu how to specify which kernel to boot by default
  • QEMU KVM Keyboard Problems Not Working Right Repeating Characters, Ctrl+C Copy and Paste not working right when using PS2 mouse in guests Solution
  • Linux how to compile binary with static sharedobjects embedded instead of dynamic to use on multi-distributions and avoid glibc compatiblity issues
  • /bin/sh: msgfmt: not found error solution on Linux Compilation Ubuntu Debian Mint Centos
  • Mikrotik RouterOS CHR/ISO Basic and Quick Setup Howto Guide
  • qemu 4 compilation options
  • CentOS 7 8 PXEBoot Netinstall Not Working Solution "Pane is dead "new value non-exisetnt xfs filesystem is not valid as a default fs type"
  • CentOS 6 EOL yum repo won't work Error: Cannot find a valid baseurl for repo: base Solution
  • CentOS 7 8 How To Disable SELinux
  • Wordpress How To Add Featured Image To Post in Hueman Theme
  • kdenlive full reset how to erase all config files
  • CentOS 7 8 yum error Trying other mirror. To address this issue please refer to the below wiki article
  • Microsoft Teams Linux - Calendar Doesn't Work Missed Meetings!
  • Scanner not working in Linux Ubuntu Fedora Mint Debian over the network? Use sane-airscan!
  • How To Boot, Install and Run Windows 2000 on QEMU-KVM
  • bash cannot execute permission denied
  • Huion and Wacom Tablets How To Install in Linux Mint / Ubuntu and make the stylus work properly
  • ffmpeg how to cut certain parts of video out