HLIBpro  2.8.1
Initialisation and Finalisation

To access HLIBpro functions and classes, we have to include the corresponding header files. Although each file can be included individually, a general header file is provided:

#include <iostream>
#include <hlib.hh>
using namespace HLIB;

All HLIBpro functions and classes, except the functions in the C language interface (see C Bindings), are encapsulated in the namespace HLIB. To simplify the calling of these functions, they are made visible in the current namespace by the using command.

Remarks
Since with hlib.hh all header files in HLIBpro are included in the current source, compilation times may be increased significantly.

Before any HLIBpro function can be used, the library has to be initialised with the INIT function:

int main ( int argc, char ** argv ) {
try {
INIT();

To use the HLIBpro error handling, which is based on exceptions, all functions are inside a try-catch block. Otherwise, the application would simply stop in case of an error.

The counterpart to this is the finalisation and the error handling:

DONE();
}// try
catch ( Error & e )
{
std::cout << e.to_string() << std::endl;
}// catch
return 0;
}

Between INIT and DONE all HLIBpro function calls and class instantiations may be placed as is illustrated in the following examples.

The code, assumed to be stored in file init.cc, is compiled with a standard C++ compiler via:

\$ c++ -o init -I<path to hlibpro>/include init.cc -L<path to hlibpro>/lib -lhpro -llapack -lblas

For convenience, a special script is shipped with HLIBpro, which provides the correct settings for compiling and linking, with which the last command simplifies to:

c++ -o init init.cc <path to hlibpro>/bin/hlib-config --cflags --lflags

# Plain Program

#include <iostream>
#include <hlib.hh>
using namespace HLIB;
int main ( int argc, char ** argv ) {
try {
INIT();
// ... HLIBpro functions
DONE();
}// try
catch ( Error & e )
{
std::cout << e.to_string() << std::endl;
}// catch
return 0;
}