GMP库,在C ++,MinGW,Code :: Blocks中编译错误

时间:2012-04-22 15:54:31

标签: c++ mingw codeblocks gmp

我为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&lt;&lt;声明文件编译并运行正常。问题可能在于重载运算符。
  2. libgmpxx.a和libgmp.a与编译器链接。它也可以在错误消息中看到......
  3. 问题可能在于libgmpxx.a。所以,我再次构建了库,但文件是相同的。
  4. 我使用本教程使用MSYS为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。
  6. 所以,我想知道的是,可能是什么问题?它怎么能解决? 而且,如果无法解决,如果您有5.0.4版本的工作文件,请分享。 :(

1 个答案:

答案 0 :(得分:2)

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

-lgmpxx -lgmp

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

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

  

链接器将仅在存档位置搜索一次存档   在命令行中指定。如果存档定义了符号   在归档之前出现的某个对象中未定义   在命令行上,链接器将包含相应的文件   来自档案馆。但是,出现的对象中存在未定义的符号   稍后在命令行上不会导致链接器搜索   再次存档。

     

请参阅 - (用于强制链接器搜索存档的方法的选项)   多次。

     

您可以在命令行上多次列出相同的存档。

相关问题