Linux 上的 GMP(MPIR) 链接器错误

GMP(MPIR) linker errors on linux

本文关键字:链接 错误 MPIR 上的 GMP Linux      更新时间:2023-10-16

我用mpir(在Windows上)写了一个公钥生成器,它工作正常。

当我尝试使用 gmp 库在 Linux 机器上编译它时,它会抛出一大堆链接器错误。

/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invali
d symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invali
d symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invali
d symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invali
d symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invali
d symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invali
d symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invali
d symbol index 13
...
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start'
:
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

我正在使用g++ -lgmp prime.cpp.我没有使用任何非 gmp 函数。知道吗?我不是在添加代码,因为代码很多。

我正在使用 g++ -lgmp prime.cpp

此命令行以两种方式断开:

  1. 您忽略了提供main的定义
  2. 您在引用库的源之前指定了库。应该是:

    g++ main.cpp prime.cpp -lgmp

    命令行上库和源/对象的顺序很重要。

更新:

有几个文件.

.主文件依赖于它们,所以在构建它之前。我正在尝试构建其他文件。

在这种情况下,正确的命令是:

# Compile, but don't link, prime.cpp
g++ -c prime.cpp