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]]
[[Category:Tutorial]]
 

Latest revision as of 17: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/.


Requirements

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

${trunk}/configure.ac

AC_PREREQ([2.68])
AC_INIT([testlib], [1.0], [BUG-REPORT-ADDRESS])
 
AM_INIT_AUTOMAKE
 
AC_PROG_CXX
 
AC_CONFIG_HEADERS([config.h])
 
AC_PROG_RANLIB
 
AC_CONFIG_FILES([Makefile 
                src/Makefile 
                src/component/Makefile])
AC_OUTPUT

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.

${trunk}/Makefile.am

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

SUBDIRS = src

${trunk}/src/Makefile.am

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.

${trunk}/src/component/Makefile.am

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