2016-06-17 50 views
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; 
} 

$ 我在C.上彩庫工作初學者我已經安裝了同等庫與GCC cygwin64。任何C/C++程序正在運行。這對於gcc編譯器來說沒有問題。但是當我嘗試使用上面的示例程序的pari庫時。我收到了很多錯誤,如下所示。如何使用gcc使用pari庫運行C程序?

此外,我使用命令$ 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 
+0

請出示你的編譯和鏈接命令 – GMichael

+0

$ GCC的測試-pari.c >>我使用這個命令進行編譯,但是我不知道如何使用鏈接命令來編譯pari庫?你能幫我麼? –

+0

那麼:「pari_close();」在節目結束時? – Adam

回答

2

您必須添加,至少,-l選項,您的命令:

gcc test-pari.c -lpari使用

最佳:

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

爲$ 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:找不到-lpari collect2:錯誤:ld返回1退出狀態 –

+0

因此libpari無法訪問。它是否安裝?它可以到達嗎?我的意思是:將libpari.so安裝到lib目錄中:'/ lib'或'/ usr/lib' – LPs

+0

而且你有一個類型:必須是'-lpari'而不是'-l pari'。 – LPs