Using PARI/GP in C++

I wanted to use PARI/GP in a C++ code and be able to compile the project with CMake.

Installing the library

On some distributions, there is a package for the PARI library.

Ubuntu & co: libpari-dev

Fedora: pari-devel

If this does not work, you can install the library manually:


Using the library

Then, in the CMakeLists.txt file, if the name of your project is temp, add the following lines:

find_library(PARI_LIBRARY pari)
target_link_libraries(temp ${PARI_LIBRARY})

Here is the code for a simple multiplication:

#include <iostream>

#include <pari/pari.h>

using namespace std;

int main( )
	GEN x(cgeti(DEFAULTPREC)), y(cgeti(DEFAULTPREC)), z(cgeti(DEFAULTPREC));
	x = stoi((long) 2);
	y = stoi((long) 6);
	z = gmul(x,y);
	cout << gtolong(z) << endl;
	return 0;



, ,


Étiquettes :


Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *