【问题标题】:GMP(MPIR) linker errors on linuxLinux上的GMP(MPIR)链接器错误
【发布时间】:2012-04-23 02:09:24
【问题描述】:

我使用 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 功能。任何想法?我没有添加代码,因为它有很多。

【问题讨论】:

  • gcc 的确切命令是什么?
  • 你能编译一个基本的(C)“hello world”程序吗?
  • @Mat- 是的,其他 C 和 C++ 程序工作正常

标签: c++ c gcc linker gmp


【解决方案1】:

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

这个命令行有两种不同的方式:

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

    g++ main.cpp prime.cpp -lgmp

    命令行matters上的库和源/对象的顺序。

更新:

有几个文件..主文件取决于它们,所以在构建它之前..我试图构建其他文件。

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

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

【讨论】:

  • 有几个文件..主文件依赖于它们,所以在构建它之前..我试图构建其他文件。
  • 耶.. 行得通。谢谢!!但在另一个文件中,gmp 无法识别mp_bitcnt_t 类型.. 说mp_bitcnt_t has not been declared
  • 您使用的是什么版本的 GMP? IIRC,mp_bitcnt_t 是在 5.0 中引入的。
猜你喜欢
  • 1970-01-01
  • 2018-07-26
  • 1970-01-01
  • 2017-07-28
  • 1970-01-01
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
相关资源
最近更新 更多