When building both static and shared libraries with cmake on Windows I have to append "-static" to the static library name (On Windows, both static an shared libraries can have the .lib extension) so the resulting file name for a static library lib is lib-static.lib. How this can be achieved with automake+libtool (i.e. instructing libtool to append "-static" to the resulting static library filename) on whatever system it is running on?
In the Autotools system with libtool
, if static and shared libraries are both being built, they are ordinarily both associated with the same libtool
library target, and they therefore have the same name, differing only in extension. This is not ordinarily a problem, because UNIX-style conventions use distinct extensions for these. In fact, it runs against UNIX convention to provide static and shared libraries with different name stems.
If you nevertheless insist on creating differently-named static and shared libraries, then your best bet is simply to define different targets for them. In the worst case, you could simply build all the sources twice:
lib_LTLIBRARIES = libfoo.la libfoo-static.la
libfoo_la_SOURCES = source1.c source2.c
# Build *only* a shared library:
libfoo_la_LDFLAGS = -shared
# use the same sources as the shared version:
# note: the underscore in "libfoo_static" is not a mistake
libfoo_static_la_SOURCES = $(libfoo_la_SOURCES)
# Build *only* a static library:
libfoo_static_la_LDFLAGS = -static
If you want to avoid the multiple compilation of your sources, however, then you should be able to create a "convenience library" from which to create both libraries:
noinst_LTLIBRARIES = libfoo_funcs.la
lib_LTLIBRARIES = libfoo.la libfoo-static.la
# A convenience library (because noinst)
# Build both static and shared versions
libfoo_funcs_la_SOURCES = source1.c source2.c
# Build *only* a shared library
libfoo_la_LDFLAGS = -shared
# Include the contents of libfoo_funcs.la
libfoo_la_LIBADD = libfoo_funcs.la
# Build *only* a static library
libfoo_static_la_LDFLAGS = -static
# Include the contents of libfoo_funcs.la
libfoo_static_la_LIBADD = libfoo_funcs.la
That only helps avoid multiple compilation of the sources if the same objects can be combined to create both static and shared libraries in the first place. This is the case on some platforms, but not the case on others.