Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define shared library major version in autoconf?

I use autoconf/automake/libtool to build a shared library. I want to pass major number of library version to shared library soname.

I have the following declaration in configure.ac:

AC_INIT([libabc], [1.1.0])

And the following Makefile.am:

AM_CPPFLAGS              = -I$(top_srcdir)/include -Wall -Wextra
LDADD                    = libabc.la

lib_LTLIBRARIES          = libabc.la
nodist_libabc_la_SOURCES = $(top_srcdir)/config.h
libabc_la_SOURCES        = $(top_srcdir)/src/abc.c

I am fine to have same version for configure script, sources and shared library soname. I can use VERSION or PACKAGE_VERSION defined in auto-generated config.h in sources, but this does not affect soname, which is always libabc.so.0.

Is there a way to enforce libtool to use my major version from AC_INIT directive? If not, what is the preferred way to define major/minor number?

like image 609
nyrl Avatar asked Dec 03 '13 11:12

nyrl


1 Answers

Versioning is quite complicated with libraries. the MAJOR.MINOR.MICRO versioning system might be adequate for some packages, but has some shortcomings.

a MICRO revision bump means that the library has internal changes - typically bug fixes - but opaque to the interface. Ideally, a shared library should be binary compatible. a MINOR revision may add functionality, but shouldn't break any of the existing API. a MAJOR revision may break the API, requiring changes to the application code.

The libtool versioning system describes a more comprehensive approach, providing rules for a current:revision:age description that you can pass to libfoo_la_LDFLAGS -version-info. There is also an alternative: libfoo_la_LDFLAGS = -release-info. This system describes a 'range' of library revisions that are compatible.

I'd recommend having a look at the configure.ac and Makefile.am files of well-established packages that use 'complex' versioning, like the GTK+, GLib libraries; and decide if you need to invest in that sort of complexity.


There are some fairly technical papers by Ulrich Drepper that describe ABI versioning toward the end. These are probably more relevant to the system libc (glibc) developers, maintaining symbol version information inside these critical libraries, along with ELF ABI support, etc. I'd stick to having a look at well-maintained infrastructure packages with good autotools support...


The AC_INIT 'version' really refers to the package release version by the maintainer, and has nothing to do with library versioning. The MAJOR.MINOR.MICRO isn't a bad idea for a source distribution, as it describes the chronology of the releases too.

like image 114
Brett Hale Avatar answered Nov 15 '22 08:11

Brett Hale