【问题标题】:How to run C program using pari library with gcc?如何使用带有 gcc 的 pari 库运行 C 程序?
【发布时间】:2016-10-19 02:43:38
【问题描述】:
#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

【问题讨论】:

  • 请显示您的编译和链接命令
  • $ gcc test-pari.c >> 我已经使用这个命令进行编译,但我不怎么使用链接命令到 pari 库?你能帮帮我吗?
  • 怎么样:“pari_close();”在程序结束时?

标签: c gcc pari


【解决方案1】:

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

gcc test-pari.c -lpari

最佳使用:

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

【讨论】:

  • $ 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退出状态
  • 所以无法访问 libpari。安装了吗?它可以到达吗?我的意思是:libpari.so 是否安装到 lib 目录中:/lib/usr/lib
  • 你有一个类型:必须是-lpari 而不是-l pari
  • 目录cygwin64/usr/local/lib/包含pari目录和libpari.a等文件。此外,我也尝试过 -lpari 。但同样的错误。是否有任何命令可以知道 pari 是否成功安装?我曾经安装过:a) ./Configure (--prefix=/exotic/dir/name 如果需要。默认是 /usr/local。) b) 全部制作,制作工作台 c) 制作安装,如果需要 d)将 misc/gprc.dft 复制到 /etc/gprc [站点范围] 或 $HOME/.gprc [个人]
  • Ok 最后一次尝试然后我就放弃了 ;) 将 dll 复制到 test-pari.exe 的同一目录或 windows 目录中并再次测试。
猜你喜欢
  • 2014-08-22
  • 2013-12-19
  • 1970-01-01
  • 2020-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多