views:

818

answers:

1

I know how to build a project or how to create a library using autoconf.

What I want to achive is to generate a static library and use this library to build a project in a single configure/make/make install run.

I want some source files to be put into library and the rest to be compiled using this library.

How do I modify makefile.am files and configure.ac to get it working?

+2  A: 

The easiest way to do this is with libtool and automake "convenience libraries". Here is a minimal example for Makefile.am

lib_LTLIBRARIES = libExample.la 
libExample_la_SOURCES = lfile1.C 
bin_PROGRAMS = test
test_SOURCES = tfile1.C 
test_LDADD = libExample.la

for configure.ac

AC_INIT(test, 1.0)
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AC_PROG_CXX
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_LTDL_DLLIB
AC_CONFIG_FILES([Makefile])
AC_OUTPUT

This will build both a static and dynamic library libExample in the directory .libs If you want just a static library, you can pass --disable-shared to configure

KeithB
I'm getting this error when running automake:src/Makefile.am:5: variable `libsadspider_la_SOURCES' is defined but no program orsrc/Makefile.am:5: library has `libsadspider_la' as canonic name (possible typo)
It sounds like you don't habe libsadspider.la listed in lib_LTLIBRARIES, or it is misspelled.
KeithB