PPL C Language Interface 2.0
PPL C Language Interface

All the declarations needed for using the PPL's C interface (preprocessor symbols, data types, variables and functions) are collected in the header file ppl_c.h. Include this header, either directly or via another header, with the directive

#include <ppl_c.h>

Building the PPL requires C++20 and C18 compilers. C18 is also called C17 by compiler toolchains. The public C header retains compatibility provisions for older C clients and can also be included from C++. Legacy C client-header checks are separate from the C18 project build.

If this directive does not work, then your compiler is unable to find the file ppl_c.h. So check that the library is installed (if it is not installed, you may want to make install, perhaps with root privileges) in the right place (if not you may want to reconfigure the library using the appropriate pathname for the --prefix option); and that your compiler knows where it is installed (if not you should add the path to the directory where ppl_c.h is located to the compiler's include file search path; this is usually done with the -I option).

The name space of the PPL's C interface is PPL_* for preprocessor symbols, enumeration values and variables; and ppl_* for data types and function names. The interface systematically uses opaque data types (generic pointers that completely hide the internal representations from the client code) and provides all required access functions. By using just the interface, the client code can exploit all the functionalities of the library yet avoid directly manipulating the library's data structures. The advantages are that (1) applications do not depend on the internals of the library (these may change from release to release), and (2) the interface invariants can be thoroughly checked (by the access functions).

Note
All functions taking as input argument an opaque pointer datatype assume that such an argument is actually referring to a valid PPL object. For instance, a function with an argument having type ppl_MIP_Problem_t will expect a valid MIP_Problem object, previously initialized by calling, e.g., ppl_new_MIP_Problem. If that is not the case (e.g., if a null pointer is passed in), the behavior is undefined. Returned handles can be owned or borrowed; constness alone does not specify ownership. See Handle Ownership and Lifetimes for ownership, lifetime and iterator requirements.

The PPL's C interface is initialized by means of the ppl_initialize function. This function must be called before using any other interface of the library. The application can release the resources allocated by the library by calling the ppl_finalize function. After this function is called no other interface of the library may be used until the interface is re-initialized using ppl_initialize.

Any application using the PPL should make sure that only the intended version(s) of the library are ever used. The version used can be checked at compile-time thanks to the macros PPL_VERSION_MAJOR, PPL_VERSION_MINOR, PPL_VERSION_REVISION and PPL_VERSION_BETA, which give, respectively major, minor, revision and beta numbers of the PPL version. For example, an application requiring major version 2 or later can use:

#if PPL_VERSION_MAJOR < 2
# error "PPL major version 2 or later is required"
#endif

Compile-time checking, however, is not normally enough, particularly in an environment where there is dynamic linking. Run-time checking can be performed by means of the functions ppl_version_major, ppl_version_minor, ppl_version_revision, and ppl_version_beta. The PPL's C interface also provides functions ppl_version, returning character string containing the full version number, and ppl_banner, returning a string that, in addition, provides (pointers to) other useful information for the library user. Version checks complement the requirement to use ABI-compatible headers and libraries. A minimum-version check does not establish compatibility with a later major release.

Use the installed pkg-config module ppl_c to obtain the compiler and linker flags for a C application. For example:

cc -std=c18 $(pkg-config --cflags ppl_c) -c myprogram.c -o myprogram.o
cc myprogram.o $(pkg-config --libs ppl_c) -o myprogram

When linking against static PPL libraries, request their private dependencies:

cc myprogram.o $(pkg-config --static --libs ppl_c) -o myprogram

The --static option supplies dependency flags; selecting static libraries remains the linker's responsibility. The metadata records the configured PPL, GMP and C++ runtime dependencies, including their library order.

The installed ppl-config program is an alternative source of configuration information:

ppl-config --interface=C --application --cppflags --cflags --ldflags

See the --help output of ppl-config and README.packaging.md in the source distribution for its output formats and usage.

For a nonstandard installation prefix, make the installed .pc files discoverable through PKG_CONFIG_PATH. Shared-library loading may also require platform-specific runtime search paths; consult your compiler and operating-system documentation.

For examples on how to use the functions provided by the C interface, you are referred to the directory demos/ppl_lpsol/ in the source distribution. It contains a Mixed Integer (Linear) Programming solver written in C. In order to use this solver you will need to install GLPK (the GNU Linear Programming Kit): this is used to read linear programs in MPS format.