Difference between revisions of "GNU build system: convenience libraries"

From GPWiki
Jump to: navigation, search
m (moved category)
Line 84: Line 84:
[[Category:GNU build system tutorial]]
[[Category:GNU build system tutorial]]

Latest revision as of 16:07, 19 April 2014

This tutorial demonstrates how to set up a GNU build system project with convenience libraries. The conveninence library consists of a set of C++ source files located in ${trunk}/src/component/.


A convenience library consists of a set of source files which, for convenience reasons, are chosen to be compiled and grouped as an independent library within the project.

In this tutorial, a small C++ project is used to demonstrate how to set a project with a convenience library. The project includes the following source files:

  • ${trunk}/src/main.c++: the project's main source file
  • ${trunk}/src/component: directory used to store the source files to be grouped as a convenience library
  • ${trunk}/src/component/component.h++ and ${trunk}/src/component/component.c++: source files used to build the convenience library

The GNU build system files are:

  • ${trunk}/configure.ac
  • ${trunk}/Makefile.am
  • ${trunk}/src/Makefile.am
  • ${trunk}/src/component/Makefile.am

Project source files


AC_INIT([testlib], [1.0], [BUG-REPORT-ADDRESS])

The main addition to this file is the inclusion of the AC_PROG_RANLIB macro, and a reference to the Makefile.am used to define the convenience library.


This is a straight-forward Makefile.am, directing Automake to build recursively in the ${trunk}/src/. directory.



SUBDIRS = component
bin_PROGRAMS    = testlib
testlib_SOURCES = main.c++
testlib_LDADD   = component/libcomponent.a

When compared with the tutorial on how to set a project following a shallow topology, there are two important additions to this file. First, there's an instruction directing Automake to build recursively in the ${trunk}/src/component/. directory, in effect adding the convenience library to the build project. Secondly, the convenience library file is also added to this project.


noinst_LIBRARIES        = libcomponent.a
libcomponent_a_SOURCES  = component.h++ component.c++

The convenience component directory is set as a regular library, with one important difference: the library is defined as noinst_.

Setting the project

After correctly setting the project files, just call autoconf to generate the configure script.

See also

External links