I want to release a C dynamic library for linux. At run time, will it be compatible with any linux version?

110 views Asked by At

My little open-source C/C++ project also offers precompiled dynamic libraries to allow other languages to bind. For Windows I just provide x86 and x64 versions. For Macos, I propose an intel x64 version and a M1/M2 version.

For Linux, I have x86 and x64 versions, but I wonder if these are compatible with any Linux version, or only with the Linux 6.2 used to produce them.

gcc -m64 -fPIC -shared -o tinyfiledialogsLinux64.so ../tinyfiledialogs.c

ldd tinyfiledialogsLinux64.so

linux-vdso.so.1 (0x00007ffdd87b3000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8afcc00000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8afd006000)

objdump -T tinyfiledialogsLinux64.so | grep GLIBC_

maximum is GLIBC_2.7
2

There are 2 answers

0
chqrlie On

Since the library is open source, there is no need nor any advantage at releasing a binary version of the library for linux. You should instead provide the source code along with a simple Makefile to produce the library or the object file for the user's target system.

You can also just document the compilation command:

gcc -m64 -fPIC -shared -o libtinyfiledialogs.so tinyfiledialogs.c
0
KamilCuk On

At run time, will it be compatible with any linux version?

No. You compiled your library against glibc. It will not be able to run out of the box on Linux without glibc, in particular on alpine Linux which uses musl.

with any Linux version,

Linux does not really have a "version". Linux is created from millions of components, and almost every single one of them has a different version. Linux kernel version is not so much relevant, as the kernel has a very strict API policy that it very rarely changes.

maximum is GLIBC_2.7

Glibc 2.7 is from 2007, so most probably you should be fine nowadays. I think linking against glibc 2.7 is more than fine and should work on any nowadays used glibc based Linux distribution.

objdump -T tinyfiledialogsLinux64.so | grep GLIBC_

This output looks nice:

objdump -T ....so | grep -o 'GLIBC_[0-9\.]*.*' | sort -u -V -t.