Search code examples
clinuxunixglibclibc

GLIBC : How to tell the executable to link to specific version of GLIBC


We are building a GTK3 application targeting Ubuntu 18.04 LTS and all the later releases. But when we build an application in Ubuntu version 20.04, that application can't run on the older Ubuntu releases. It says

libc.so.6: version `GLIBC_2.31' not found (required by .source)

But if I build an application on Ubuntu 18.04, it will work on all the later Ubuntu releases. Ubuntu 18.04 has GLIBC version 2.27 by default and this version will work on all the later releases.

So is there any way to tell my application that, the application is built with GLIBC 2.27 irrespective of what version the OS in which the application is built has? Is there any way to feed this information of the GLIBC version to the application during the build process?


Solution

  • How to tell the executable to link to specific version of GLIBC

    You can't.

    The hack offered by Antonio Petricca (and elsewhere) is likely to introduce very subtle bugs, and is ill-advised.

    The right way to fix this is to perform compile and link against the minimal version of GLIBC you need to run with. That could be done by

    • building on an older system
    • building in a chroot environment
    • building in a docker container
    • creating a Linux-to-older-Linux cross-compiler and using it to build the program.