获取gmp库 [英] Getting gmp libraries to

查看:102
本文介绍了获取gmp库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用以下程序编译程序时遇到问题:

I am having a problem getting a program to compile using:

最新的Msys和MinGW安装 Windows 7 Pro/英特尔酷睿I5/8GB

Latest Msys and MinGW installations Windows 7 Pro / Intel Core I5 / 8GB

GMP 5.1.2库 -头文件在C:\ gmp \ include中 -.a和.la文件位于C:\ gmp \ lib

GMP 5.1.2 libraries - the header file is in C:\gmp\include - the .a and .la files are in C:\gmp\lib

我最初将此问题发布为Eclipse问题,但沉默一直震耳欲聋.从那以后,我尝试仅在msys中使用gcc进行编译,但遇到了同样的问题.我使用以下代码进行编译:

I originally posted this as an Eclipse question, but the silence has been deafening. I have since tried compiling using just gcc in msys, and I get the same problem. I compile using:

g ++ -I/c/gmp/include -O0 -g3 -Wall -c -fmessage-length = 0 -o main.o ./main.cpp

g++ -I /c/gmp/include -O0 -g3 -Wall -c -fmessage-length=0 -o main.o ./main.cpp

,它似乎已成功完成.然后,我使用以下链接:

which appears to complete successfully. Then I link using:

g ++ -L/c/gmp/lib -o GMPDebug.exe main.o

g++ -L /c/gmp/lib -o GMPDebug.exe main.o

结果:

main.o:在函数main': C:\Users\Clay\workspace\GMPDebug\Debug/../main.cpp:22: undefined reference to __ gmpz_init_set_str'中 collect2.exe:错误:ld返回1退出状态

main.o: In function main': C:\Users\Clay\workspace\GMPDebug\Debug/../main.cpp:22: undefined reference to__gmpz_init_set_str' collect2.exe: error: ld returned 1 exit status

程序非常简单-足以使库正常工作:

The program is very very simple - just enough to get the libraries working:

#include <getopt.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <iostream>
#include <gmpxx.h>
#include <gmp.h>

using namespace std;

int main ()
{
    mpz_t p;
    mpz_init_set_str (p,"3",10); 

    return 0;
}

所有包含项都是因为我从一个较大的程序中删除了此内容.任何想法如何解决这个问题?

All of the includes are because I pared this down from a larger program. Any idea how to fix this?

谢谢!

推荐答案

此处是使用Eclipse CDT,MinGW和msys for C ++设置当前(截至13年7月2日)GNU bignum库的正确过程.为了解决这个问题,您应该以前使用过Unix或Linux,以及Windows,并且对编程和编译程序的了解还很模糊.这是一个多星期的研究和无聊的挫折的结果,因此,如果我把某些东西弄乱了,请客气地把它记下来,否则我会以我的力量炸毁你!

Here is the correct procedure for setting up the current (as of 7/2/13) GNU bignum libraries with Eclipse CDT, MinGW, and msys for C++. To get through this, you should have used Unix or Linux before, as well as Windows, and you should have a vague recollection of programming and compiling programs. This is the culmination of over a week of research and hardcore frustration, so if I messed something up note it politely or I will blow you up with the power of my mind!

1)我假设您已经下载并安装了Eclipse和MinGW,并且已将msys安装到MinGW中.您必须在msys之前安装MinGW!

1) I assume you have already downloaded and installed Eclipse and MinGW and have installed msys into MinGW. You must install MinGW before msys!

2)将GMP库的压缩包从gmplib.org下载到$ {gmp_download}.我下载了gmp-5.1.2.tar.xz,因为我从未使用过lzip,也不知道它是否在msys中可用.

2) Download the tarball for the GMP libraries from gmplib.org to ${gmp_download}. I downloaded the gmp-5.1.2.tar.xz because I have never used lzip and didn't know if it was available in msys.

3)打开一个msys窗口(本质上是一个bash shell). cd $ {gmp_buid}和tar -Jxvf $ {gmp_download}/gmp-x.x.x.tar.xz

3) Open up an msys window (essentially a bash shell). cd ${gmp_buid} and tar -Jxvf ${gmp_download}/gmp-x.x.x.tar.xz

这些tar选项与您在网络上其他地方所看到的不同! -Jxvf适用于xz(我认为是lzip),但对于gzip,则使用-xzvf.

Those tar options are different from what you may find elsewhere on the web! -Jxvf is right for xz (and I think lzip), but for gzip you use -xzvf.

4)cd gmp-x.x.x并运行./config.guess.记下输出.接下来,您将需要它.

4) cd gmp-x.x.x and run ./config.guess. Write down the output. You will need it next.

5)运行./configure --prefix = $ {gmp_build} --build =< config.guess输出> --enable-cxx --with-gnu-ld

5) Run ./configure --prefix=${gmp_build} --build=<config.guess output> --enable-cxx --with-gnu-ld

显然,如果您没有明确告诉GMP为您的平台构建,它将构建所有内容,这很不好. cxx选项构建C ++库,而--with-gnu-ld允许它与ld一起使用.很简单.

Apparently if you don't explicitly tell GMP to build for your platform it builds everything, which is bad. The cxx option builds the C++ libraries and --with-gnu-ld allows it to work with ld. Pretty straightforward.

6)制造

7)进行安装

EX:假设您已安装到C:/gmp.您应该具有gmp/include/gmp.h和gmpxx.h.您还应该具有gmp/lib/libgmp.a,libgmp.la,libgmpxx.a,libgmpxx.la.您还应该有一个包含目录的共享目录.

EX: suppose you installed to C:/gmp. You should have gmp/include/gmp.h and gmpxx.h. You should also have gmp/lib/libgmp.a, libgmp.la, libgmpxx.a, libgmpxx.la. You should also have a share directory with stuff in it.

8)设置月食:

  • 转到项目->属性
  • 在C/C ++构建下->环境编辑PATH变量并添加$ {gmp_build}/include; $ {gmp_build}/lib
  • 在C/C ++构建下->设置->工具设置-> GCC汇编程序->常规添加$ {gmp_build}/include作为包含路径.
  • 位置相同,但-> GCC C ++编译器->包含将$ {gmp_build}/include添加为包含路径.
  • 相同的地方-> GCC C ++编译器->其他将-lgmp -lgmpxx添加到该行的末尾.线的尽头!
  • 相同的地方-> GCC C编译器添加与以前相同的包含路径和其他选项.
  • 相同位置-> MinGW C ++链接器->库 gmpxx gmp 都添加到库(-l)"中!现在,将$ {gmp_build}/lib添加到库搜索路径(-L)"
  • 在C/C ++常规下->路径&符号->包含选项卡,请检查您的Assembly,C和C ++的包含目录中是否有$ {gmp_build}/include.如果不存在,请添加它们.它们可能已经由Eclipse填充.
  • 同一个地方->库"选项卡,检查您的订单中是否有 gmp gmpxx .它应该已经被填充.​​
  • 相同位置->库路径"选项卡检查$ {gmp_build}/lib是否应该已经存在.
  • 点击应用",并确保您重建索引,否则更改将不会生效.点击确定以关闭.
  • Go to project --> properties
  • Under C/C++ build --> Environment edit the PATH variable and add ${gmp_build}/include;${gmp_build}/lib
  • Under C/C++ build --> settings --> tool settings --> GCC Assembler --> general add ${gmp_build}/include as an include path.
  • Same place but --> GCC C++ compiler --> Includes add ${gmp_build}/include as an include path.
  • Same place --> GCC C++ compiler --> Miscellaneous add -lgmp -lgmpxx to the END of the line. THE END OF THE LINE!
  • Same place --> GCC C compiler Add the same include paths and miscellaneous options as before.
  • Same place --> MinGW C++ linker --> Libraries Add to the "Libraries (-l)" both gmpxx and gmp IN THAT ORDER! Now add ${gmp_build}/lib to "Library Search Path (-L)"
  • Under C/C++ General --> Paths & Symbols --> Incudes Tab check that you have ${gmp_build}/include in your include directories for Assembly, C, and C++. If they aren't there add them. They might already be populated by Eclipse.
  • Same place --> Libraries Tab check that you have gmp and gmpxx IN THAT ORDER. It should already be populated.
  • Same Place --> Library Paths Tab Check for ${gmp_build}/lib which should already be there.
  • Hit "Apply" and make sure you rebuild the index or the changes won't take. Hit OK to close out.

9)运行此简短程序以验证您的设置:

9) Run this short program to verify your setup:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <gmp.h>
#include <gmpxx.h>

using namespace std;

int main ()
{
    mpz_t p;
    mpz_init_set_ui (p,3);

    return 0;
}

您的编译命令应类似于以下内容:

Your compile commands should look similar to this:

g ++"-IC:\ gmp \ include" -O0 -g3 -Wall -c -fmessage-length = 0 -lgmp -lgmpxx -o main.o".. \ main.cpp"

g++ "-IC:\gmp\include" -O0 -g3 -Wall -c -fmessage-length=0 -lgmp -lgmpxx -o main.o "..\main.cpp"

g ++"-LC:\ gmp \ lib" -o GMPDebug.exe main.o -lgmpxx -lgmp

g++ "-LC:\gmp\lib" -o GMPDebug.exe main.o -lgmpxx -lgmp

注意:

1)选项的顺序很重要.我不知道所有原因,但是如果第二个命令行(链接程序)在-o选项之前具有-lgmp -lgmpxx标志,则链接将失败.

1) The order of the options is important. I don't know all of the whys, but if the second command line (which links the program) has the -lgmp -lgmpxx flags before the -o option, the linking will fail miserably.

2)-l标志是一个棘手的标志.它实际上说的是去-L< whatever>寻找liblibrary.a".在这种情况下,在C:\ gmp \ lib中查找libgmp.a和libgmpxx.a".

2) The -l flag is a tricky one. It actually says "Go look in -L<whatever> for liblibrary.a". In this case "Go look in C:\gmp\lib for libgmp.a and libgmpxx.a".

3)我听说过涉及cout和64位版本的eclipse的错误,所以我使用的是32位版本,在那里我看到了相同的错误. :-(

3) I have heard of bugs involving cout and the 64 bit version of eclipse, so I am using the 32 bit version, where I am seeing the same bug. :-(

4)如果在链接器中将gmp放在gmpxx之前,那么重载的运算符将不起作用.

4) If you place gmp before gmpxx in the linker, your overloaded operators won't work.

这篇关于获取gmp库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆