Next: , Previous: GMP Basics, Up: GMP Basics   [Index]


3.1 Headers and Libraries

All declarations needed to use GMP are collected in the include file gmp.h. It is designed to work with both C and C++ compilers.

#include <gmp.h>

Note however that prototypes for GMP functions with FILE * parameters are only provided if <stdio.h> is included too.

#include <stdio.h>
#include <gmp.h>

Likewise <stdarg.h> is required for prototypes with va_list parameters, such as gmp_vprintf. And <obstack.h> for prototypes with struct obstack parameters, such as gmp_obstack_printf, when available.

All programs using GMP must link against the libgmp library. On a typical Unix-like system this can be done with ‘-lgmp’, for example

gcc myprogram.c -lgmp

GMP C++ functions are in a separate libgmpxx library. This is built and installed if C++ support has been enabled (see Build Options). For example,

g++ mycxxprog.cc -lgmpxx -lgmp

GMP is built using Libtool and an application can use that to link if desired, see GNU Libtool in GNU Libtool.

If GMP has been installed to a non-standard location then it may be necessary to use ‘-I’ and ‘-L’ compiler options to point to the right directories, and some sort of run-time path for a shared library.