gpt4 book ai didi

c++ - GMP 库,C++、MinGW、Code::Blocks 中的编译错误

转载 作者:太空狗 更新时间:2023-10-29 21:48:37 34 4
gpt4 key购买 nike

我已经为 MinGW 构建了 GMP。我使用的 IDE 是 Code::Blocks。我对 GMP 的 C 函数没有任何问题。但是我在使用 C++ 时遇到了问题。我尝试运行的程序就是这么简单,

#include<iostream>
#include<gmpxx.h>
using namespace std;

main()
{
mpz_class a;
a=12345;
cout<<"value"<<a<<"\n";
return 0;
}

我得到的错误是

F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osmpz.o):osmpz.cc|| undefined reference to `__gmpz_get_str'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x1c)||undefined reference to `__gmp_asprintf_memory'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osfuns.o):osfuns.cc:(.rdata+0x20)||undefined reference to `__gmp_asprintf_reps'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_doprnt_integer'|
F:\Compilers\C_Libraries\GMP\lib\libgmpxx.a(osdoprnti.o):osdoprnti.cc|| undefined reference to `__gmp_asprintf_final'|
||=== Build finished: 5 errors, 0 warnings ===|

现在,一些额外的数据:

  1. 我对 C 函数没有任何问题。而且,如果我删除 cout<< 语句,文件编译并运行良好。问题可能出在运算符重载上。
  2. libgmpxx.a 和 libgmp.a 与编译器链接。它也可以在错误消息中看到...
  3. 问题可能出在 libgmpxx.a 上。所以,我再次构建了库,但文件是一样的。
  4. 我使用本教程使用 MSYS for MinGW 构建 GMP。 http://www.cs.nyu.edu/exact/core/gmp/http://suchideas.com/journal/2007/07/installing-gmp-on-windows/
  5. 我使用的 GMP 版本是 5.0.4。

那么,我想知道的是,可能是什么问题?怎么解决呢?并且,如果无法解决并且您有 5.0.4 版本的工作文件,请分享。 :(

最佳答案

我怀疑构建程序的命令以错误的顺序指定了 libgmp* 库。确保在 libgmpxx.a 库之后指定了 libgmp.a 库:

-lgmpxx -lgmp

如果它们以其他顺序指定,那么当从 libgmpxx.a 库中提取依赖项时,将不会搜索 libgmp.a 库。

来自ld linker's docs on the -l option :

The linker will search an archive only once, at the location where it is specified on the command line. If the archive defines a symbol which was undefined in some object which appeared before the archive on the command line, the linker will include the appropriate file(s) from the archive. However, an undefined symbol in an object appearing later on the command line will not cause the linker to search the archive again.

See the -( option for a way to force the linker to search archives multiple times.

You may list the same archive multiple times on the command line.

关于c++ - GMP 库,C++、MinGW、Code::Blocks 中的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10269464/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com