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:
- Download the latest version of the sources here: http://pari.math.u-bordeaux.fr/download.html
- Extract the archive and open a terminal inside this folder.
- Execute the following commands:
./Configure sudo make install
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( )
{
pari_init(1000000,2);
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;
}
Laisser un commentaire