manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

B.0.2 Example of a package using GiNaC

The following shows how to build a simple package using automake and the ‘PKG_CHECK_MODULES’ macro. The program used here is ‘simple.cpp’:

 
#include <iostream>
#include <ginac/ginac.h>

int main()
{
    GiNaC::symbol x("x");
    GiNaC::ex a = GiNaC::sin(x);
    std::cout << "Derivative of " << a 
              << " is " << a.diff(x) << std::endl;
    return 0;
}

You should first read the introductory portions of the automake Manual, if you are not already familiar with it.

Two files are needed, ‘configure.ac’, which is used to build the configure script:

 
dnl Process this file with autoreconf to produce a configure script.
AC_INIT([simple], 1.0.0, bogus@example.net)
AC_CONFIG_SRCDIR(simple.cpp)
AM_INIT_AUTOMAKE([foreign 1.8])

AC_PROG_CXX
AC_PROG_INSTALL
AC_LANG([C++])

PKG_CHECK_MODULES(SIMPLE, ginac >= 1.3.7)

AC_OUTPUT(Makefile)

The ‘PKG_CHECK_MODULES’ macro does the following: If a GiNaC version greater or equal than 1.3.7 is found, then it defines SIMPLE_CFLAGS and SIMPLE_LIBS. Otherwise, it dies with the error message like

 
configure: error: Package requirements (ginac >= 1.3.7) were not met:

Requested 'ginac >= 1.3.7' but version of GiNaC is 1.3.5

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables SIMPLE_CFLAGS
and SIMPLE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

And the ‘Makefile.am’, which will be used to build the Makefile.

 
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = simple
simple_SOURCES = simple.cpp
simple_CPPFLAGS = $(SIMPLE_CFLAGS)
simple_LDADD = $(SIMPLE_LIBS)

This ‘Makefile.am’, says that we are building a single executable, from a single source file ‘simple.cpp’. Since every program we are building uses GiNaC we could have simply added SIMPLE_CFLAGS to CPPFLAGS and SIMPLE_LIBS to LIBS. However, it is more flexible to specify libraries and complier options on a per-program basis.

To try this example out, create a new directory and add the three files above to it.

Now execute the following command:

 
$ autoreconf -i

You now have a package that can be built in the normal fashion

 
$ ./configure
$ make
$ make install

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.