Next: , Previous: , Up: Introduction   [Contents][Index]


1.6 Building Sources

If you want to compile a source file including the libTMCG.hh header, you must make sure that the compiler can find it in the directory hierarchy. This is achieved by adding the path of the corresponding directory to the compilers include file search path.

However, the path to the include file has been determined at the time the source is configured. To solve this problem, LibTMCG ships with a small helper program libTMCG-config that knows the path to the include file and a few other configuration options. The options that need to be added to the compiler invocation are output by the --cflags option to libTMCG-config. The following example shows how it can be used at the command line:

g++ -c foo.cc `libTMCG-config --cflags`

Adding the output of ‘libTMCG-config --cflags’ to the compilers command line will ensure that the compiler can find the LibTMCG header file.

A similar problem occurs when linking your program with LibTMCG. Again, the compiler has to find the library files. Therefore the correct installation path has to be added to the library search path. To achieve this, the option --libs of libTMCG-config can be used. For convenience, this option also outputs all other stuff (e.g. required third-party libraries) that is required to link your program with LibTMCG (in particular, the ‘-lTMCG’ option).

The example shows how to link foo.o with LibTMCG to a program called foo:

g++ -o foo foo.o `libTMCG-config --libs`

Of course, you can also combine both examples to a single command by calling the shell script libTMCG-config with both options:

g++ -o foo foo.c `libTMCG-config --cflags --libs`

1.6.1 Building Sources Using GNU Automake

You can use GNU Automake to obtain automatically generated Makefiles. If you do so then you do not have to care about finding and invoking the libTMCG-config script at all. LibTMCG provides an Automake extension that does all the stupid work for you.

Macro: AM_PATH_LIBTMCG ([minimum-version], [action-if-found], [action-if-not-found])

Check whether LibTMCG (at least version minimum-version, if given) exists on the host system. If it is found, execute action-if-found, otherwise do action-if-not-found.

Additionally, the macro defines LIBTMCG_CFLAGS to the flags needed for compilation in order to find the necessary header files, and LIBTMCG_LIBS to the corresponding linker flags.

You can use the defined variables in your Makefile.am as follows:

AM_CPPFLAGS = $(LIBTMCG_CFLAGS)
LDADD = $(LIBTMCG_LIBS)

Next: , Previous: , Up: Introduction   [Contents][Index]