找回密码
 欢迎注册
查看: 51312|回复: 24

[分享] 在Windows下编译GMP以供VC使用

[复制链接]
发表于 2013-1-16 11:44:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
在本站有过许多这个话题的许多讨论,特别是《mathe能否提供更新的windows版gmp库》,见http://bbs.emath.ac.cn/viewthread.php?tid=2669。不过,这些帖子回复次数太多,内容较分散,我总结了一下,贴在这里,公大家使用时参考。
精华
1. 下载和安装 MinGW 安装程序 1.1打开浏览器,google "MinGW", 找到其网页 [http://sourceforge.net/projects/mingw/files] 1.2下载安装程序,我这里下载的是mingw-get-inst-20120426.exe 1.3运行这个安装程序,使用下列选项(其中有些组件可能不是必须的) a) 目标目录选择默认值c:\MinGW b) 组件选择"C Compiler","C++ Compiler ","MSSYS Basic System"和"MinGW Developer ToolKit". 2. 下载GMP源码包。 2.1 打开浏览器,进入网站[http://gmplib.org/] 2.2 下载最新的源码包,我这里下载的是gmp-5.1.0.tar.bz2 2.3 解压缩这个压缩包到你希望的子目录。我这里使用winRar解压到[D:\lbc\GMP\gmp-5.1.0] 3 下载pexports, 我这里下载的是pexports.zip,解压后的文件是pexports.exe(20K,2008-9-22创建),复制到MinGW的Bin目录,我这里复制到[C:\MinGW\bin]。 注:复制到其他已在环境变量path中定义的目录也可以。 4. 设置MinGW环境的目录mount信息,修改[C:\MinGW\msys\1.0\etc\fstab],将GMP目录添加msys文件系统根目录,我这里添加的是"D:\lbc\GMP\gmp-5.1.0 /gmp",所以在MinGW中,可以使用"cd /gmp"进入到gmp源码包目录。 5. 使用MinGW编译GMP。 5.1 点击开始菜单的"MinGw/minGW shell", 进入MinGW shell. 5.2 依次执行下面的4个命令 ./configure --disable-static --enable-shared make make check make install 注: 1. 因为windows下的VC编译器不能识别静态库.a文件,故使用参数"--disable-static --enable-shared" 编译为.dll格式的动态库文件. 2. 我这里当执行make check时,63个test case中,有1个没过。错误出在函数mpz_kronecker当运行t-jac.exe时。 3. 上面的几个命令需要很长时间,比在Linux编译GMP要慢的多。 6. 执行下面的命令,生成VC需要的lib文件.我这里为了区分版本,把libgmp-10换成libgmp-5.1.0. cd /usr/local/bin mv libgmp-10.dll libgmp-5.1.0.dll pexports.exe libgmp-5.1.0.dll > libgmp-5.1.0.def lib /def:libgmp-5.1.0.def 7. 复制相应的文件到指定的目录,以方便VC使用。 7.1. 复制gmp.h到VC工程文件源码目录或者你指定的公用目录。在第1种情况,在你的c文件中使用gmp.h时,你需要使用相对路径。在第2种情况,你可以不用写路径名,但需要对修改VC的includes的选项,具体方法见8#. 7.2. 复制dll文件到你的执行文件所在的目录或指定的公用目录。 7.3. 复制lib文件到你VC工程文件源码目录或指定的公用目录,并将这个lib文件添加到工程中。 注: 依赖于MinGW的安装路径,编译后的.h和.dll文件的路径可能是不同的。默认情况文件在.h文件在C:\MinGW\msys\1.0\local\include", .dll文件在"C:\MinGW\msys\1.0\local\bin" 8. 如果.h文件和.dll文件在公用目录(所有的工程文件共享同样的设置),你需要设置VC的"Includes", "Library files"和"Executable files",在VC6,你可以进入"Tools->Options->Directories中进行设置. 在VC2008,你需要进入Tools->Options->Projects and Solutions->VC++ Directories 进行设置。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-2-20 20:30:25 | 显示全部楼层
呵呵,很详细啊,支持下
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-2-20 21:35:57 | 显示全部楼层
2# 无心人 无心人 大神出山了, 祝贺下,
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-2-20 21:36:40 | 显示全部楼层
只是来看看你们
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-5-9 18:26:08 | 显示全部楼层
纠正下梁宝宝 我们的讨论已经证明.a可以在某种程度上被VC识别了, 所以,GMP能编译成静态库了
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-5-11 10:14:28 | 显示全部楼层
我对.a和.lib这两种静态库的内部差异 还真不太清楚。 把MinGW编译出来的.a 换一下后缀名,改成.lib就能被VS调用吗
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-5-30 18:40:17 | 显示全部楼层
发现用这个方法,之前编译的dll [core2 E8500] #define GMP_LIMB_BITS 32 #define GMP_NAIL_BITS 0
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-6-4 10:52:56 | 显示全部楼层
8# G-Spider 貌似话没说完, 之前编译的dll的bug可以get around?
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-6-4 20:23:43 | 显示全部楼层
9# wayne 1. 关于运行库问题,再放在这里吧。 在gmp.info-1中有一段说明: MINGW uses the C runtime library ‘msvcrt.dll' for I/O, so applications wanting to use the GMP I/O routines must be compiled with `cl /MD' to do the same. If one of the other C runtime library choices provided by MS C is desired then the suggestion is to use the GMP string functions and confine I/O to the application. 所以在编译的时候加一句/MD 即可(默认使用msvcrt.dll作为运行库),上面的程序vc6.0测试通过。 但是: 启用 /MD 时VC6,VS2008,vs2010 分别对应msvcrt.dll、 msvcr80.dll 、MSVCR100.dll。 所以经常看到用vc6.0以上版本的开发软件(涉及运行库),会顺便捎上***.dll 系统库。 有篇文章涉及到这个问题,说的有点意思: Dynamically linking with MSVCRT.DLL using Visual C++ 2005 “A question arises, what does Microsoft do? They deploy their applications to a variety of Windows environments. A look at Windbg’s dependencies showed it’s using MSVCRT.DLL rather than one of the newer CRTs. Microsoft’s new Network Monitor 3.1 also uses MSVCRT.DLL. Windows Desktop Search is also using the old, trusty CRT. How can all these new applications be using the vintage CRT? They’re not still using the antique, unsupported Visual C++ 6.0, are they? Well, no. The answer is more complicated and can be found in the Windows Driver Kit (WDK). ” 所以wayne加了/MD 同样没有成功,我用vc6.0编译运行成功了。 这里附件有个相关的解决方案: VC2010程序使用系统自带的MSVCRT.pdf (206.52 KB, 下载次数: 2) 2. gmp对2^32的基支持的很好,此时GMP_NAIL_BITS=0(默认的编译情形下),一些汇编相关的mpn的优化也是针对这种情形。GMP_NAIL_BITS>0的情形支持的不是很好--enable-nails,有些函数不支持,整体编译不过。如GCD.c:
  1. #if GMP_NAIL_BITS > 0
  2. //~ /* Nail supports should be easy, replacing the sub_ddmmss with nails
  3. //~ * logic. */
  4. #error Nails not supported.
  5. #endif
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2013-6-4 20:25:14 | 显示全部楼层
  1. `configure' configures GNU MP 5.1.2 to adapt to many kinds of systems.
  2. Usage: ./configure [OPTION]... [VAR=VALUE]...
  3. To assign environment variables (e.g., CC, CFLAGS...), specify them as
  4. VAR=VALUE. See below for descriptions of some of the useful variables.
  5. Defaults for the options are specified in brackets.
  6. Configuration:
  7. -h, --help display this help and exit
  8. --help=short display options specific to this package
  9. --help=recursive display the short help of all the included packages
  10. -V, --version display version information and exit
  11. -q, --quiet, --silent do not print `checking ...' messages
  12. --cache-file=FILE cache test results in FILE [disabled]
  13. -C, --config-cache alias for `--cache-file=config.cache'
  14. -n, --no-create do not create output files
  15. --srcdir=DIR find the sources in DIR [configure dir or `..']
  16. Installation directories:
  17. --prefix=PREFIX install architecture-independent files in PREFIX
  18. [/usr/local]
  19. --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
  20. [PREFIX]
  21. By default, `make install' will install all the files in
  22. `/usr/local/bin', `/usr/local/lib' etc. You can specify
  23. an installation prefix other than `/usr/local' using `--prefix',
  24. for instance `--prefix=$HOME'.
  25. For better control, use the options below.
  26. Fine tuning of the installation directories:
  27. --bindir=DIR user executables [EPREFIX/bin]
  28. --sbindir=DIR system admin executables [EPREFIX/sbin]
  29. --libexecdir=DIR program executables [EPREFIX/libexec]
  30. --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
  31. --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
  32. --localstatedir=DIR modifiable single-machine data [PREFIX/var]
  33. --libdir=DIR object code libraries [EPREFIX/lib]
  34. --includedir=DIR C header files [PREFIX/include]
  35. --oldincludedir=DIR C header files for non-gcc [/usr/include]
  36. --datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
  37. --datadir=DIR read-only architecture-independent data [DATAROOTDIR]
  38. --infodir=DIR info documentation [DATAROOTDIR/info]
  39. --localedir=DIR locale-dependent data [DATAROOTDIR/locale]
  40. --mandir=DIR man documentation [DATAROOTDIR/man]
  41. --docdir=DIR documentation root [DATAROOTDIR/doc/gmp]
  42. --htmldir=DIR html documentation [DOCDIR]
  43. --dvidir=DIR dvi documentation [DOCDIR]
  44. --pdfdir=DIR pdf documentation [DOCDIR]
  45. --psdir=DIR ps documentation [DOCDIR]
  46. Program names:
  47. --program-prefix=PREFIX prepend PREFIX to installed program names
  48. --program-suffix=SUFFIX append SUFFIX to installed program names
  49. --program-transform-name=PROGRAM run sed PROGRAM on installed program names
  50. System types:
  51. --build=BUILD configure for building on BUILD [guessed]
  52. --host=HOST cross-compile to build programs to run on HOST [BUILD]
  53. Optional Features:
  54. --disable-option-checking ignore unrecognized --enable/--with options
  55. --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
  56. --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
  57. --enable-maintainer-mode enable make rules and dependencies not useful
  58. (and sometimes confusing) to the casual installer
  59. --enable-assert enable ASSERT checking [[default=no]]
  60. --enable-alloca how to get temp memory [[default=reentrant]]
  61. --enable-cxx enable C++ support [[default=no]]
  62. --enable-assembly enable the use of assembly loops [[default=yes]]
  63. --enable-fft enable FFTs for multiplication [[default=yes]]
  64. --enable-old-fft-full enable old mpn_mul_fft_full for multiplication
  65. [[default=no]]
  66. --enable-nails use nails on limbs [[default=no]]
  67. --enable-profiling build with profiler support [[default=no]]
  68. --enable-fat build a fat binary on systems that support it
  69. [[default=no]]
  70. --enable-minithres choose minimal thresholds for testing [[default=no]]
  71. --enable-shared[=PKGS] build shared libraries [default=yes]
  72. --enable-static[=PKGS] build static libraries [default=yes]
  73. --enable-fast-install[=PKGS]
  74. optimize for fast installation [default=yes]
  75. --disable-libtool-lock avoid locking (might break parallel builds)
  76. Optional Packages:
  77. --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
  78. --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
  79. --with-readline readline support in calc demo program
  80. [[default=detect]]
  81. --with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
  82. both]
  83. --with-gnu-ld assume the C compiler uses GNU ld [default=no]
  84. --with-sysroot=DIR Search for dependent libraries within DIR
  85. (or the compiler's sysroot if not specified).
  86. Some influential environment variables:
  87. ABI desired ABI (for processors supporting more than one ABI)
  88. CC C compiler command
  89. CFLAGS C compiler flags
  90. LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
  91. nonstandard directory <lib dir>
  92. LIBS libraries to pass to the linker, e.g. -l<library>
  93. CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
  94. you have headers in a nonstandard directory <include dir>
  95. CPP C preprocessor
  96. CC_FOR_BUILD
  97. build system C compiler
  98. CPP_FOR_BUILD
  99. build system C preprocessor
  100. CXX C++ compiler command
  101. CXXFLAGS C++ compiler flags
  102. CXXCPP C++ preprocessor
  103. M4 m4 macro processor
  104. YACC The `Yet Another Compiler Compiler' implementation to use.
  105. Defaults to the first program found out of: `bison -y', `byacc',
  106. `yacc'.
  107. YFLAGS The list of arguments that will be passed by default to $YACC.
  108. This script will default YFLAGS to the empty string to avoid a
  109. default value of `-d' given by some make applications.
  110. Use these variables to override the choices made by `configure' or to help
  111. it to find libraries and programs with nonstandard names/locations.
  112. Report bugs to <gmp-bugs@gmplib.org, see http://gmplib.org/manual/Reporting-Bugs.html>.
  113. GNU MP home page: <http://www.gnu.org/software/gmp/>.
  114. General help using GNU software: <http://www.gnu.org/gethelp/>.
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-11-22 03:22 , Processed in 0.030021 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表