2
#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",GENtostr(k));
 return 0;
}

$ I'm a beginner to work on pari library in C. I've installed pari library in cygwin64 with gcc. Any C/C++ program is running. That is no problem with gcc compiler. But when I was trying to use pari library for the above sample program. I was getting many errors as follows.

Moreover, I use the command $ gcc test-pari.c to run the program. Actually I also need to know how to run a program written using pari library in C. Do I need to show some library explicitly during run. Any suggestions?

/tmp/cc7ELKK4.o:test-pari.c:(.text+0x87): undefined reference to `pari_err'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x87): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `pari_err'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x230): undefined reference to `pari_err'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x230): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `pari_err'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x253): undefined reference to `pari_init'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x253): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `pari_init'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x27f): undefined reference to `gadd'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x27f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `gadd'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x28f): undefined reference to `GENtostr'
/tmp/cc7ELKK4.o:test-pari.c:(.text+0x28f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `GENtostr'
/tmp/cc7ELKK4.o:test-pari.c:(.rdata$.refptr.gen_1[.refptr.gen_1]+0x0): undefined reference to `gen_1'
/tmp/cc7ELKK4.o:test-pari.c:(.rdata$.refptr.gen_0[.refptr.gen_0]+0x0): undefined reference to `gen_0'
/tmp/cc7ELKK4.o:test-pari.c:(.rdata$.refptr.bot[.refptr.bot]+0x0): undefined reference to `bot'
/tmp/cc7ELKK4.o:test-pari.c:(.rdata$.refptr.avma[.refptr.avma]+0x0): undefined reference to `avma'
collect2: error: ld returned 1 exit status
LPs
  • 16,045
  • 8
  • 30
  • 61

1 Answers1

3

You have to add, at least, -l option to your command:

gcc test-pari.c -lpari

Best using:

gcc test-pari.c -Wall -Wextra -pedantic -lpari -std=c11 -g -o test-pari 
LPs
  • 16,045
  • 8
  • 30
  • 61
  • Getting error again for $ gcc test-pari.c -Wall -Wextra -pedantic -l pari -std=c11 -g -o test-pari /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lpari collect2: error: ld returned 1 exit status – Tushar Saha Jun 17 '16 at 10:18
  • So libpari is not reachable. Is it installed? Is it reachable? I mean: is libpari.so installed into a lib dir: `/lib` or `/usr/lib` – LPs Jun 17 '16 at 10:19
  • And you have a type: must be `-lpari` not `-l pari`. – LPs Jun 17 '16 at 10:21
  • Directory cygwin64/usr/local/lib/ contain pari directory and libpari.a and some other files. Moreover, I've tried both -lpari also. But same error. Is there any command to know pari is successfully installed or not? I've used to install: a) ./Configure ( --prefix=/exotic/dir/name if desired. Default is /usr/local. ) b) make all, make bench c) make install, if desired d) copy misc/gprc.dft to /etc/gprc [sitewide] or $HOME/.gprc [personal] – Tushar Saha Jun 17 '16 at 10:29
  • Try adding `-L` option: `gcc test-pari.c -Wall -Wextra -pedantic -L/usr/local/lib -lpari -std=c11 -g -o test-pari` – LPs Jun 17 '16 at 10:32
  • Now running ok but output file error: $ ./test-pari.exe cygwin64/home/Tushar/pari-2.7.5/examples/test-pari.exe: error while loading shared libraries: libpari-gmp.dll: cannot open shared object file: No such file or directory. But this file exists. – Tushar Saha Jun 17 '16 at 10:47
  • @TusharSaha the file exists but is not reachable by library path. I don' know ho to set `ldconfig` in `cygwin`. Fast think you can do is to copy all `libpari*.*` into `/usr/lib` and retry – LPs Jun 17 '16 at 11:42
  • Thanks @LPs for your wonderful cooperation. Actually my pari library directory is cygwin64\usr\local\lib and it already contains the required files are there. No need to copy. It also contains libpari-gmp.dll file. I don't know what the actual problem? – Tushar Saha Jun 17 '16 at 12:16
  • I'm not getting you. You should try to move files from `/usr/local/lib` into `/usr/lib` because of `/usr/lib` is one of the dirs where the system looks for libraries. So get it a shot if you can. `/usr/local/lib` it isn't a default supported location for libs. – LPs Jun 17 '16 at 12:37
  • Now I've copied usr/local/lib to usr/lib but same error !! – Tushar Saha Jun 17 '16 at 12:56
  • 1
    Ok last try then I'll give up ;) Copy dll to the same dir of `test-pari.exe` or into windows directory and test it again. – LPs Jun 17 '16 at 13:00
  • Perfect! Good job ;) Remember to close the question as answered. – LPs Jun 17 '16 at 13:17