在本站有过许多这个话题的许多讨论,特别是《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 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 进行设置。
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编译运行成功了。
这里附件有个相关的解决方案:
-
`configure' configures GNU MP 5.1.2 to adapt to many kinds of systems.
-
-
Usage: ./configure [OPTION]... [VAR=VALUE]...
-
-
To assign environment variables (e.g., CC, CFLAGS...), specify them as
-
VAR=VALUE. See below for descriptions of some of the useful variables.
-
-
Defaults for the options are specified in brackets.
-
-
Configuration:
-
-h, --help display this help and exit
-
--help=short display options specific to this package
-
--help=recursive display the short help of all the included packages
-
-V, --version display version information and exit
-
-q, --quiet, --silent do not print `checking ...' messages
-
--cache-file=FILE cache test results in FILE [disabled]
-
-C, --config-cache alias for `--cache-file=config.cache'
-
-n, --no-create do not create output files
-
--srcdir=DIR find the sources in DIR [configure dir or `..']
-
-
Installation directories:
-
--prefix=PREFIX install architecture-independent files in PREFIX
-
[/usr/local]
-
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
-
[PREFIX]
-
-
By default, `make install' will install all the files in
-
`/usr/local/bin', `/usr/local/lib' etc. You can specify
-
an installation prefix other than `/usr/local' using `--prefix',
-
for instance `--prefix=$HOME'.
-
-
For better control, use the options below.
-
-
Fine tuning of the installation directories:
-
--bindir=DIR user executables [EPREFIX/bin]
-
--sbindir=DIR system admin executables [EPREFIX/sbin]
-
--libexecdir=DIR program executables [EPREFIX/libexec]
-
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
-
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
-
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
-
--libdir=DIR object code libraries [EPREFIX/lib]
-
--includedir=DIR C header files [PREFIX/include]
-
--oldincludedir=DIR C header files for non-gcc [/usr/include]
-
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
-
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
-
--infodir=DIR info documentation [DATAROOTDIR/info]
-
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
-
--mandir=DIR man documentation [DATAROOTDIR/man]
-
--docdir=DIR documentation root [DATAROOTDIR/doc/gmp]
-
--htmldir=DIR html documentation [DOCDIR]
-
--dvidir=DIR dvi documentation [DOCDIR]
-
--pdfdir=DIR pdf documentation [DOCDIR]
-
--psdir=DIR ps documentation [DOCDIR]
-
-
Program names:
-
--program-prefix=PREFIX prepend PREFIX to installed program names
-
--program-suffix=SUFFIX append SUFFIX to installed program names
-
--program-transform-name=PROGRAM run sed PROGRAM on installed program names
-
-
System types:
-
--build=BUILD configure for building on BUILD [guessed]
-
--host=HOST cross-compile to build programs to run on HOST [BUILD]
-
-
Optional Features:
-
--disable-option-checking ignore unrecognized --enable/--with options
-
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
-
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
-
--enable-maintainer-mode enable make rules and dependencies not useful
-
(and sometimes confusing) to the casual installer
-
--enable-assert enable ASSERT checking [[default=no]]
-
--enable-alloca how to get temp memory [[default=reentrant]]
-
--enable-cxx enable C++ support [[default=no]]
-
--enable-assembly enable the use of assembly loops [[default=yes]]
-
--enable-fft enable FFTs for multiplication [[default=yes]]
-
--enable-old-fft-full enable old mpn_mul_fft_full for multiplication
-
[[default=no]]
-
--enable-nails use nails on limbs [[default=no]]
-
--enable-profiling build with profiler support [[default=no]]
-
--enable-fat build a fat binary on systems that support it
-
[[default=no]]
-
--enable-minithres choose minimal thresholds for testing [[default=no]]
-
--enable-shared[=PKGS] build shared libraries [default=yes]
-
--enable-static[=PKGS] build static libraries [default=yes]
-
--enable-fast-install[=PKGS]
-
optimize for fast installation [default=yes]
-
--disable-libtool-lock avoid locking (might break parallel builds)
-
-
Optional Packages:
-
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
-
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
-
--with-readline readline support in calc demo program
-
[[default=detect]]
-
--with-pic[=PKGS] try to use only PIC/non-PIC objects [default=use
-
both]
-
--with-gnu-ld assume the C compiler uses GNU ld [default=no]
-
--with-sysroot=DIR Search for dependent libraries within DIR
-
(or the compiler's sysroot if not specified).
-
-
Some influential environment variables:
-
ABI desired ABI (for processors supporting more than one ABI)
-
CC C compiler command
-
CFLAGS C compiler flags
-
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
-
nonstandard directory <lib dir>
-
LIBS libraries to pass to the linker, e.g. -l<library>
-
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
-
you have headers in a nonstandard directory <include dir>
-
CPP C preprocessor
-
CC_FOR_BUILD
-
build system C compiler
-
CPP_FOR_BUILD
-
build system C preprocessor
-
CXX C++ compiler command
-
CXXFLAGS C++ compiler flags
-
CXXCPP C++ preprocessor
-
M4 m4 macro processor
-
YACC The `Yet Another Compiler Compiler' implementation to use.
-
Defaults to the first program found out of: `bison -y', `byacc',
-
`yacc'.
-
YFLAGS The list of arguments that will be passed by default to $YACC.
-
This script will default YFLAGS to the empty string to avoid a
-
default value of `-d' given by some make applications.
-
-
Use these variables to override the choices made by `configure' or to help
-
it to find libraries and programs with nonstandard names/locations.
-
-
Report bugs to <gmp-bugs@gmplib.org, see http://gmplib.org/manual/Reporting-Bugs.html>.
-
GNU MP home page: <http://www.gnu.org/software/gmp/>.
-
General help using GNU software: <http://www.gnu.org/gethelp/>.
复制代码