so-versions vs. program versions

April 11, 2010

One must not use the so-version of a library as a release version or vice versa. A release version is something that people use for things like VCS tags, tarballs, and the "Version:" field of pkgconfig .pc files, among others.

The reinterpretation of the so-version as a release number makes it a useless number and does not necessarily reflect new APIs that have been added. If you entered a pkgconfig Version: 0.1.0 for libcryptsetup.so.0.1.0, that would be wrong because the library is providing the 1.x API. A program would not be able to test for the presence of it.

The difference lies — among other considerations — in the changed meaning and ordering:

sub so_sort
{
        my @a = split(/\./, $a);
        my @b = split(/\./, $b);
        return $a[0] + $a[1] <=> $b[0] + $b[1];
}

sub ver_sort
{
        my @a = split(/\./, $a);
        my @b = split(/\./, $b);
        return $a[0] <=> $b[0] || $a[1] <=> $b[1] || $a[2] <=> $b[2];
}

@t = qw(0.0.0 0.1.0 0.2.0 1.0.0 1.1.0 2.0.0);
print "SO_SORT:  ", join(" ", sort so_sort @t), "\n";
print "VER_SORT: ", join(" ", sort ver_sort @t), "\n";

SO_SORT:  0.0.0 0.1.0 1.0.0 0.2.0 1.1.0 2.0.0
VER_SORT: 0.0.0 0.1.0 0.2.0 1.0.0 1.1.0 2.0.0

The pkgconfig Version: uses the “ver_sort” meaning. Trying to stuff so-versions into it is not going to work.

Further reading