All declarations needed to use GMP are collected in the include file gmp.h, except for the C++ Class Interface which comes with its own separate header gmpxx.h. gmp.h is designed to work with both C and C++ compilers.
Note however that prototypes for GMP functions with
FILE * parameters
are only provided if
<stdio.h> is included before.
#include <stdio.h> #include <gmp.h>
<stdarg.h> is required for prototypes with
parameters, such as
<obstack.h> for prototypes
struct obstack parameters, such as
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, including the C++ Class Interface but also C++ Formatted Output for regular GMP types. 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.