PPL6-Icon Patrick's Programming Library Version 6.4.21 - Dokumentation
PPL6 verwenden

Programmcode

Innerhalb des Programmcodes ist darauf zu achten, dass die notwendigen Header-Dateien eingebunden werden. Die Basisfunktionalität ist in der Datei "ppl6.h" zu finden. Diese sollte daher immer eingebunden werden:

#include <ppl6.h>

Wird von weiteren Features gebrauch gemacht, können folgende weitere Include-Dateien benötigt werden:

#include <ppl6-grafix.h>
#include <ppl6-sound.h>
#include <ppl6-tk.h>

Damit die Include-Dateien gefunden werden, sollte der Compiler mit der Ausgabe von "ppl6-config --cflags" gestartet werden, und der Linker mit "ppl6-config --libs".

Da alle Funktionen der Library im Namespace "ppl6" zu finden sind, muss dies bei der Verwendung berücksichtigt werden. Dazu gibt es zwei Möglichkeiten:

  • 1. Globale Verwendung der Funktionen
    Dazu fügt man am Anfang des Programmcodes folgenden Code ein:
    using namespace ppl6;
    Danach sind alle Funktionen sofort mit ihrem Namen aufrufbar.

Makefile

Das folgende Beispiel soll als Template für ein Makefile dienen. Wichtig sind die beiden Zeilen "CFLAGS" und "LIB", in denen das Tool "ppl6-config" aufgerufen wird. Das Keywort "debug" sagt dem Programm, dass die Debug-Version der Library verwendet werden soll. Für eine Release-Version sollte aus Performancegründen das Keywort "release" verwendet werden oder ganz weggelassen werden. Außerdem empfiehlt es sich die Kompiler Optimierungen zu aktivieren, indem man bei den CFLAGS "-O2" oder "-O3" hinzufügt.

CC = gcc
EXTRA_CFLAGS =
INCLUDE = -I. -I../include
CFLAGS = -ggdb -Wall $(INCLUDE) $(EXTRA_CFLAGS) `ppl6-config --cflags debug`
LIB = -lstdc++ `ppl6-config --libs debug`
PROGRAM = ppltestprog
OBJECTS=compile/main.o
$(PROGRAM): compile Makefile $(OBJECTS)
$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJECTS) $(LIB)
-chmod 755 $(PROGRAM)
all: $(PROGRAM)
clean:
-rm -f compile $(PROGRAM) *.log debug.txt *.core
install: $(PROGRAM)
cp $(PROGRAM) /usr/local/bin
compile:
-mkdir compile
compile/main.o: main.cpp testprog.h Makefile
$(CC) $(CFLAGS) -o compile/main.o -c main.cpp

Verwendung von "autoconf"

Soll autoconf zur Erkennung der PPL-Library verwendet werden, kann folgendes m4-Makro verwendet werden:

ppl6.m4

dnl AX_PATH_LIB_PPL6([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
AC_DEFUN([AX_PATH_LIB_PPL6],[dnl
AC_ARG_WITH([libppl6],
[ --with-libppl6[[=PATH]] Prefix where PPL6-Library is installed],
[ppl6_prefix="$withval"],
[ppl6_prefix="no"])
#if test "$ppl6_prefix" != "no"
#then
if test "$ppl6_prefix" = "no"
then
AC_PATH_PROG(ppl6config,ppl6-config)
elif test "$ppl6_prefix" != "yes"
then
ppl6config="$ppl6_prefix/bin/ppl6-config"
else
AC_PATH_PROG(ppl6config,ppl6-config)
fi
AC_MSG_CHECKING([for lib ppl6])
if test [ -z "$ppl6config" ]
then
AC_MSG_RESULT(no)
AC_MSG_ERROR([ppl6 library (libppl6) and/or headers not found])
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT(yes)
min_ppl_version=ifelse([$1], ,6.0.0,[$1])
AC_MSG_CHECKING(for ppl6 version >= $min_ppl_version)
ppl_version=`${ppl6config} --version`
ppl_config_major_version=`echo $ppl_version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
ppl_config_minor_version=`echo $ppl_version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
ppl_config_micro_version=`echo $ppl_version | \
sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
ppl_config_version=`expr $ppl_config_major_version \* 10000 + $ppl_config_minor_version \* 100 + $ppl_config_micro_version`
ppl_req_major_version=`echo $min_ppl_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
ppl_req_minor_version=`echo $min_ppl_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
ppl_req_micro_version=`echo $min_ppl_version | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
ppl_req_version=`expr $ppl_req_major_version \* 10000 + $ppl_req_minor_version \* 100 + $ppl_req_micro_version`
if test $ppl_config_version -lt $ppl_req_version
then
AC_MSG_RESULT([no, have $ppl_version])
ifelse([$3], , :, [$3])
else
AC_MSG_RESULT([yes (version $ppl_version) ])
#AC_MSG_CHECKING(ppl6 debug libraries)
LIBPPL6_DEBUG_LIBS=`${ppl6config} --libs debug`
#AC_MSG_RESULT($LIBPPL6_DEBUG_LIBS)
#AC_MSG_CHECKING(ppl6 release libraries)
LIBPPL6_RELEASE_LIBS=`${ppl6config} --libs release`
LIBPPL6_RELEASE_ARCHIVE=`${ppl6config} --archive release`
LIBPPL6_DEBUG_ARCHIVE=`${ppl6config} --archive debug`
#AC_MSG_RESULT($LIBPPL6_RELEASE_LIBS)
#AC_MSG_CHECKING(ppl6 includes)
LIBPPL6_CFLAGS=`${ppl6config} --cflags`
LIBPPL6=`${ppl6config} --ppllib release`
LIBPPL6_DEBUG=`${ppl6config} --ppllib debug`
#AC_MSG_RESULT($LIBPPL6_CFLAGS)
ifelse([$2], , :, [$2])
fi
fi
#else
# AC_MSG_RESULT(not configured)
# AC_MSG_ERROR([ppl6 library is required])
#fi
])
dnl AX_PPL6_FEATURE([FEATURE, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
AC_DEFUN([AX_PPL6_FEATURE],[dnl
AC_MSG_CHECKING([for ppl6-feature: $1])
if test -z "${ppl_features}"
then
ppl_features=`${ppl6config} --features`
fi
echo ${ppl_features}| tr " " "\n" | grep -i "^$1" > /dev/null 2>&1
if test $? -eq 0
then
AC_MSG_RESULT(yes)
ifelse([$2], , :, [$2])
else
AC_MSG_RESULT(no)
ifelse([$3], , :, [$3])
fi
])

Das Makro kann beispielsweise so im Configure-Script verwendet werden:

sinclude(autoconf/ppl6.m4)
report_have_ppl6="no"
AX_PATH_LIB_PPL6([6.2.4],
AC_DEFINE(HAVE_LIBPPL6, 1, [ Define if you have ppl6. ])
report_have_ppl6="yes"
AC_SUBST(LIBPPL6_CFLAGS)
AC_SUBST(LIBPPL6)
AC_SUBST(LIBPPL6_DEBUG)
AC_SUBST(LIBPPL6_DEBUG_LIBS)
AC_SUBST(LIBPPL6_RELEASE_LIBS)
,
AC_MSG_ERROR(no suitable ppl6 available)
)

Seit Version 6.3.1 gibt es noch ein weiteres Macro. um das vorhandensein eines bestimmten Features abzufragen. Dieses würde im configure nach dem obrigen Aufruf so eingebunden:

AX_PPL6_FEATURE([zlib],ppl_has_zlib="yes",ppl_has_zlib="no")
AX_PPL6_FEATURE([bzip2],ppl_has_bzip2="yes",ppl_has_bzip2="no")
...

Denkbar wäre auch:

AX_PPL6_FEATURE([zlib],,AC_MSG_ERROR(a required feature is missing))

Das Makefile aus dem Beispiel oben würde dann so aussehen:

CC = gcc
EXTRA_CFLAGS =
INCLUDE = -I. -I../include
CFLAGS = -ggdb -Wall $(INCLUDE) $(EXTRA_CFLAGS) @LIBPPL6_CFLAGS@
LIB = -lstdc++ @LIBPPL6_RELEASE_LIBS@
PROGRAM = ppltestprog
OBJECTS=compile/main.o
$(PROGRAM): compile Makefile $(OBJECTS)
$(CC) $(CFLAGS) -o $(PROGRAM) $(OBJECTS) $(LIB)
-chmod 755 $(PROGRAM)
all: $(PROGRAM)
clean:
-rm -f compile $(PROGRAM) *.log debug.txt *.core
install: $(PROGRAM)
cp $(PROGRAM) /usr/local/bin
compile:
-mkdir compile
compile/main.o: main.cpp testprog.h Makefile
$(CC) $(CFLAGS) -o compile/main.o -c main.cpp