Compiling the Example

To compile this example you have to compile your source code and link it with libmlp-cpp library file and xerces-c library. Here you see a simple Makefile (Too see compleete simple makefile look into examples/example_other/example1_simple.tar.gz).

CXXFLAGS= -g -Wall -c


#libraries to link with
LIBS=-lxerces-c -lmlp-cpp


all:
    gcc -MMD -MP $(CXXFLAGS) main.cpp -o main.o
    gcc -o example-guide.bin main.o ${LIBS}

This can only work if you have properly installed MLP library and Xerces-c library. You need to properly set environment variables so the linker knows where the libraries and headers are installed. On Linux libraries are searched according to /etc/ld.so.cahe. Default path is most often /usr/lib. If you install MLP library into the /usr, Makefile displayed above should work. If you plan to install MLP library in some nonstandard directory you need to properly set environment variables and paths to headers.

Name of the environment variable that specifies where linker look for libraries depends on your system. For most UNIX platforms it is LD_LIBRARY_PATH. On AIX it is LIBPATH, on Mac OS X it is DYLD_LIBRARY_PATH, and on HP-UX it is SHLIB_PATH. For Cigwin or MinGW Windows PATH variable is used.

Other way to use MLP library in your project is to use GNU auto tools. You can use pkg-config in your configure.ac file to configure your project to automatically read information from libmlp-cpp.pc and use them to create Makefile. You need to properly set $PKG_CONFIG_PATH environment variable for pkg-config to find libmlp-cpp.pc. On the following program listing you can see the part of configure.ac that check availability of libmlp-cpp.pc and xerces-c.pc and reads information from them to variables. This variables are then substituted in Makefile.am. (Too see compleete autotools configure.ac and Makefile.am look into examples/example_other/example1_autotools.tar.gz).

Part of configure.ac:

PKG_CHECK_MODULES(LIBMLP, libmlp-cpp)
AC_SUBST(LIBMLP_CFLAGS)
AC_SUBST(LIBMLP_LIBS)

PKG_CHECK_MODULES(XERCESC, xerces-c)
AC_SUBST(XERCESC_CFLAGS)
AC_SUBST(XERCESC_LIBS)

Part of Makefile.am:

INCLUDES = -I@top_srcdir@ @XERCESC_CFLAGS@ @LIBMLP_CFLAGS@

noinst_PROGRAMS = example-guide.bin
example_guide_bin__SOURCES = main.cpp
example_guide_bin_LDADD = @XERCESC_LIBS@ @LIBMLP_LIBS@

For example if you installed MLP library into /var/libmlp-cpp your libmlp-cpp.pc file would be in /var/libmlp-cpp/lib/pkgconfig. Then to compile your program you would execute:

example $ export $PKG_CONFIG_PAHT=/var/libmlp-cpp/lib/pkgconfig; ./configure
example $ make

This way libmlp-cpp.pc file is found by pkg-config and LIBMLP_CFLAGS and LIBMLP_LIBS are filled with proper path to MLP library headers and libraries.