Search code examples
gccubuntu-16.04pari

GEN variables not identified - PARI library C


I have recently installed PARI library on ubuntu 16.04. The set of examples provided with the source are running correctly but , if I use "gun", "ghalf", etc., gcc compilation fails with error :

error: ‘gun’ undeclared (first use in this function)

I am new to this library and know very little about it. Can anybody please help me in fixing this error.

This is the code that I am trying to compile :

#include<stdio.h>  
#include <pari/pari.h>  
int main(void)  
{  
 GEN i,j,k;  
 pari_init(500000,2);  
 i=gun;  
 j=stoi(3);  
 k=gadd(i,j);  
 printf("1+3=%s\n",GENtostr(k));  
 return 0;  
} 

Solution

  • It looks like you're using code intended for a very old version of PARI. Modern versions use gen_1 rather than gun for the constant 1. With this change,

    gcc -o test-pari test-pari.c -lpari && ./test-pari
    

    yields

    1+3=4

    as desired. Alternatively (not recommended!), if you're trying to port a lot of old code, you could add

    #define PARI_OLD_NAMES
    

    before

    #include <pari/pari.h>  
    

    and the code with work with gun.