简体   繁体   English

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

[英]GMP Library, compile error in C++, MinGW, Code::Blocks

I have built GMP for MinGW. 我为MinGW建立了GMP。 The IDE I'm using is Code::Blocks. 我正在使用的IDE是Code :: Blocks。 I don't have any problems with C functions of GMP. 我对GMP的C函数没有任何问题。 But I'm having problem with C++. 但是我遇到了C ++的问题。 The program I tried to run is as simple as this, 我试图运行的程序就像这样简单,

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

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

And the Errors I get are 我得到的错误是

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 ===|

Now, some additional data: 现在,一些额外的数据:

  1. I don't have any problem with C functions. 我对C函数没有任何问题。 And also, if I remove cout<< statement the file compiles and runs fine. 而且,如果我删除cout <<语句文件编译并运行正常。 The problem is probably with overloaded operators. 问题可能在于重载运算符。
  2. libgmpxx.a and libgmp.a are linked with compiler. libgmpxx.a和libgmp.a与编译器链接。 It can be seen in the error messages too... 它也可以在错误消息中看到......
  3. The problem is probably with the libgmpxx.a alone. 问题可能在于libgmpxx.a。 So, I built the Library again, but the files are same. 所以,我再次构建了库,但文件是相同的。
  4. I used this tutorial build GMP with MSYS for MinGW. 我使用本教程使用MSYS为MinGW构建GMP。 http://www.cs.nyu.edu/exact/core/gmp/ and http://suchideas.com/journal/2007/07/installing-gmp-on-windows/ http://www.cs.nyu.edu/exact/core/gmp/http://suchideas.com/journal/2007/07/installing-gmp-on-windows/
  5. The version of GMP I'm using is 5.0.4. 我正在使用的GMP版本是5.0.4。

So, what I want to know is, what could be the problem? 所以,我想知道的是,可能是什么问题? And how could it be solved? 它怎么能解决? And, if unsolvable and if you have the working files for 5.0.4 version, please share it. 而且,如果无法解决,如果您有5.0.4版本的工作文件,请分享。 :( :(

I suspect the command to build your program specifies the libgmp* libraries in the wrong order. 我怀疑构建程序的命令以错误的顺序指定了libgmp*库。 Make sure the libgmp.a library is specified after the libgmpxx.a library: 确保在libgmp.a库之后指定了libgmpxx.a库:

-lgmpxx -lgmp

If they are specified in the other order, then when pulling in dependencies from libgmpxx.a library, the libgmp.a library won't be searched. 如果以其他顺序指定它们,那么当从libgmpxx.a库中提取依赖libgmpxx.a ,将不会搜索libgmp.a库。

From the ld linker's docs on the -l option : 来自ld链接器的-l选项上的文档

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. 您可以在命令行上多次列出相同的存档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM