How to define shared library major version in autoconf?
Asked Answered
T

3

5

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?

Talebearer answered 3/12, 2013 at 11:28 Comment(0)
M
8

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.

Methane answered 3/12, 2013 at 15:33 Comment(1)
Thank you for answer. Lets assume I have basic knowledge of ABI maintaining, even if I do not follow it closely while library is being developed. Also, I am fine to assume that AC_INIT 'version' is exactly the same as library ABI version. Also, I would like to stick to abc.so.X.Y naming style instead of abc-X.Y.so, although that is questionable. So the question is rather technical - what should I write in configure.ac and Makefile.am to pass version to SONAME being generated in a simple way. Do I get it right that you suggest to use LT_VERSION_INFO tricks from GTK as reference design?Talebearer
P
0

Setting it to zero is worse than assigning a x.y.z revision that changes each time. Whilst it is not ideal, the x.y.z will prevent version collisions on many cases.

Use the -Wl,-soname,libXXX.so.1.0 linker argument.

Plast answered 19/5, 2017 at 14:9 Comment(0)
P
0

from https://phab.enlightenment.org/w/autotoolsintegration/

m4_define([v_maj], [1])
m4_define([v_min], [1])
m4_define([v_mic], [0])
m4_define([lt_cur], m4_eval(v_maj + v_min))
m4_define([project_version], [v_maj.v_min.v_mic])

m4_define([lt_cur], [m4_eval([v_maj] + [v_min])])
m4_define([lt_rev], [v_mic])
m4_define([lt_age], [v_min])
version_info="lt_cur:lt_rev:lt_age"
AC_SUBST([version_info])

AC_INIT([my_project], [project_version], [[email protected]])

and src/lib/Makefile.am is:

MAINTAINERCLEANFILES = Makefile.in
 
include_HEADERS = Foo.h
 
lib_LTLIBRARIES = libfoo.la
 
libfoo_la_SOURCES  = foo1.c foo2.c
libfoo_la_LDFLAGS = -version-info @version_info@

Note (2021.09.19): m4_eval fixed
Note (2021.09.20): add AC_INIT

Pastrami answered 6/10, 2018 at 6:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.