1 Introduction

1.1 What is Pnl

Pnl is a scientific library written in C and distributed under the Gnu Lesser General Public Licence (LGPL). This manual is divided into four parts.

1.2 A few helpful conventions

1.3 Using Pnl

In this section, we assume that the library is installed in the directory $HOME/pnl-xxx.

Once installed, the library can be found in the $HOME/pnl-xxx/lib directory and the header files in the $HOME/pnl-xxx/include directory.

1.3.1 Compiling and Linking

The header files of the library are installed in a root pnl directory and should always be included with this pnl/ prefix. So, for instance to use random number generators you should include

#include <pnl/pnl_random.h>

Compiling and linking by hand. If gcc or llvm is used, you should pass the following options

This does not work straight away on all OS especially if the library is not installed in a standard directory namely /usr/ or /usr/local/ for which you need a privileged writing access. On some systems, you may need to add to the linker flags the dependencies of the library, which can become very tedious. Therefore, we provide a second automatic mechanism which takes care of the dependencies on its own.

Compiling and linking using an automatic Makefile. This mechanism only works under Unix (it has been tested under various Linux distributions and Mac OS X).

First, you need to create a new directory wherever you want, put in all your code and create a Makefile as below

To define your target just add the executable name, say my-exec, to the BINS list and create an entry my_exec_SRC carrying the list of source files needed to create your executable. Note that if dashes ’-’ may appear in an executable name, the name of the associated variable holding the list of source files is obtained by replacing dashes with underscores ’_’ and adding the _SRC suffix.

Assume you want to create two binaries : my-exec based on mixed C and C++ code (file1.c and file2.cpp) and mybinary based on poo1.cxx and poo2.cpp. You can use the following Makefile.

## Flags passed to the linker 
LDFLAGS= 
 
## Flags passed to the compiler 
CFLAGS= 
 
## list of executables to create 
BINS=my-exec mybinary 
 
my_exec_SRC=file1.c file2.cpp 
# optional flags for compiling and linking 
my_exec_CFLAGS= 
my_exec_CXXFLAGS= 
my_exec_LDFLAGS= 
 
mybinary_SRC=poo1.cxx poo2.cpp 
# optional flags for compiling and linking 
mybinary_CFLAGS= 
mybinary_CXXFLAGS= 
mybinary_LDFLAGS= 
 
 
## This line must be the last one 
include full_path_to_pnl_build/CMakeuser.incl

Let us comment a little the different variables

An example of such a Makefile can be found in pnl-xxx/perso.

Warning: if a file appears in the source list of several binairies, the flags used to compile this file are determined by the ones of the first binary involving this file. In the following example main.cpp will always be compiled with the flag -O3 even for generating bin2

BINS=bin1 bin2 
 
bin1_SRC=main.cpp poo1.c 
my_exec_CXXFLAGS=-O3 
 
bin2_SRC=main.cpp poo2.c 
mybinary_CXXFLAGS=-g -O0 
 
## This line must be the last one 
include full_path_to_pnl_build/CMakeuser.incl

Compiling and linking using CMake. If you already use CMake for your new project, just add the following to your toplevel CMakeLists.txt

find_package(Pnl REQUIRED) 
set(LIBS ${LIBS} ${PNL_LIBRARIES}) 
include_directories(${PNL_INCLUDE_DIRS}) 
# Deactivate PNL debugging stuff on Release builds 
if(${CMAKE_BUILD_TYPE} STREQUAL "Release") 
    add_definitions(-DPNL_RANGE_CHECK_OFF) 
endif()

Then, call cmake with the following extra flag

-DCMAKE_PREFIX_PATH=path/to/build-dir

or add the variable CMAKE_BUILD_TYPE to the GUI.

Just in case, we give an example of a complete although elementary CMakeLists.txt

1.3.2 Inline Functions and getters

If it is supported by your compiler, getter and setter functions are declared as inline functions. This is automatically detected when running CMake. By default, setter and getter functions check that the required access is valid, basically it boils down to checking whether the index of the access is within an acceptable range. These extra tests can become very expensive when getter and setter functions are intensively called.

Thus, it is possible to alter this default behaviour by defining the macro PNL_RANGE_CHECK_OFF. This macro is automatically defined when the library is compiled in Release mode, ie. with -DCMAKE_BUILD_TYPE=Release passed to CMake.