如何使用带有gcc的pari库运行C程序?

时间:2016-06-17 09:55:56

标签: c gcc pari

#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;
}

$ 我是C语言中的pari库的初学者。我已经使用gcc在cygwin64中安装了pari库。任何C / C ++程序都在运行。这对gcc编译器来说没问题。但是当我尝试使用pari库进行上述示例程序时。我收到的错误如下。

此外,我使用命令$ gcc test-pari.c来运行程序。实际上我还需要知道如何在C中运行使用pari库编写的程序。我是否需要在运行期间显式地显示一些库。有什么建议吗?

/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

1 个答案:

答案 0 :(得分:3)

您必须在命令中添加至少-l选项:

gcc test-pari.c -lpari

最佳使用:

gcc test-pari.c -Wall -Wextra -pedantic -lpari -std=c11 -g -o test-pari