首页 > 未分类 > MinGW自带的MSYS中使用新版本GMP编译PPL

MinGW自带的MSYS中使用新版本GMP编译PPL

在MinGW自带的MSYS(理论上来讲单独配置的MSYS整合MinGW也可能出现这个问题。)中使用新版本GMP编译PPL(动态链接)可能会出现以下错误:

checking for the GMP library version 4.1.3 or above... no
configure: error: Cannot find GMP version 4.1.3 or higher.
GMP is the GNU Multi-Precision library:
see http://www.swox.com/gmp/ for more information.
When compiling the GMP library, do not forget to enable the C++ interface:
add --enable-cxx to the configuration options.

在config.log里面可以查到如下错误细节:

configure:10021: checking for the GMP library version 4.1.3 or above
configure:10110: g++ -o conftest.exe  -g -O2 -frounding-math   -I/mingwlibs/include  conftest.cpp  -L/mingwlibs/lib -lgmpxx -lgmp >&5
configure:10110: $? = 0
configure:10110: ./conftest.exe
GMP header (gmpxx.h) and library (ligmpxx.*) version mismatch:
header gives 5.0.4;
library gives 5.0.1.
configure:10110: $? = 1
configure: program exited with status 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "the Parma Polyhedra Library"
| #define PACKAGE_TARNAME "ppl"
| #define PACKAGE_VERSION "0.12"
| #define PACKAGE_STRING "the Parma Polyhedra Library 0.12"
| #define PACKAGE_BUGREPORT "ppl-devel@cs.unipr.it"
| #define PACKAGE_URL ""
| #define PPL_CONFIGURE_OPTIONS " '--disable-static' '--enable-shared' '--with-gmp=/mingwlibs' '--prefix=/mingwlibs' '--host=i686-pc-mingw32' 'host_alias=i686-pc-mingw32'"
| #define PPL_NDEBUG 1
| #define PPL_FPMATH_MAY_USE_387 1
| #define PPL_FPMATH_MAY_USE_SSE 1
| #define PPL_COEFFICIENT_TYPE mpz_class
| #define PPL_COEFFICIENT_BITS 0
| #define PPL_GMP_INTEGERS 1
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_TYPEOF 1
| #define SIZEOF_CHAR 1
| #define SIZEOF_SHORT 2
| #define SIZEOF_INT 4
| #define SIZEOF_LONG 4
| #define SIZEOF_LONG_LONG 8
| #define SIZEOF_SIZE_T 4
| #define SIZEOF_FLOAT 4
| #define SIZEOF_DOUBLE 8
| #define SIZEOF_LONG_DOUBLE 12
| #define SIZEOF_INTP 4
| #define SIZEOF_FP 4
| #define HAVE_FENV_H 1
| #define PPL_CAN_CONTROL_FPU 1
| #define PPL_CXX_PLAIN_CHAR_IS_SIGNED 1
| #define PPL_CXX_PROVIDES_PROPER_LONG_DOUBLE 1
| #define PPL_CXX_FLOAT_BINARY_FORMAT PPL_FLOAT_IEEE754_SINGLE
| #define PPL_CXX_FLOAT_EXACT_OUTPUT 0
| #define PPL_SUPPORTED_FLOAT 0
| #define PPL_CXX_DOUBLE_BINARY_FORMAT PPL_FLOAT_IEEE754_DOUBLE
| #define PPL_CXX_DOUBLE_EXACT_OUTPUT 1
| #define PPL_SUPPORTED_DOUBLE 1
| #define PPL_CXX_LONG_DOUBLE_BINARY_FORMAT PPL_FLOAT_INTEL_DOUBLE_EXTENDED
| #define PPL_CXX_LONG_DOUBLE_EXACT_OUTPUT 1
| #define PPL_SUPPORTED_LONG_DOUBLE 1
| #define PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS 1
| #define PPL_CXX_SUPPORTS_IEEE_INEXACT_FLAG 1
| #define PPL_CXX_SUPPORTS_ATTRIBUTE_WEAK 1
| #define HAVE_FENV_H 1
| #define HAVE_GETOPT_H 1
| #define HAVE_SIGNAL_H 1
| #define HAVE_STRING_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DECL_FFS 0
| #define HAVE_DECL_GETENV 1
| #define HAVE_DECL_STRTOF 1
| #define HAVE_DECL_STRTOD 1
| #define HAVE_DECL_STRTOLD 1
| #define HAVE_DECL_STRTOLL 1
| #define HAVE_DECL_STRTOULL 1
| #define HAVE_DECL_FMA 1
| #define HAVE_DECL_FMAF 1
| #define HAVE_DECL_FMAL 1
| #define HAVE_DECL_RINTF 1
| #define HAVE_DECL_RINTL 1
| #define HAVE_INT_FAST16_T 1
| #define HAVE_INT_FAST32_T 1
| #define HAVE_INT_FAST64_T 1
| #define HAVE_UINT_FAST16_T 1
| #define HAVE_UINT_FAST32_T 1
| #define HAVE_UINT_FAST64_T 1
| #define HAVE_UINTPTR_T 1
| /* end confdefs.h.  */
| 
| #include <gmpxx.h>
| #include <climits>
| #include <string>
| #include <sstream>
| #include <iostream>
| 
| #if __GNU_MP_VERSION < 4 || (__GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR < 1) || (__GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR == 1 && __GNU_MP_VERSION_PATCHLEVEL < 3)
| #GMP version 4.1.3 or higher is required
| #endif
| 
| #ifndef BITS_PER_MP_LIMB
| #define BITS_PER_MP_LIMB GMP_LIMB_BITS
| #endif
| 
| int
| main() {
|   std::string header_version;
|   {
|     std::ostringstream s(header_version);
|     s << __GNU_MP_VERSION << "." << __GNU_MP_VERSION_MINOR;
|     // Starting from GMP version 4.3.0, the gmp_version variable
|     // always contains three parts.  In previous versions the
|     // patchlevel was omitted if it was 0.
|     if (__GNU_MP_VERSION_PATCHLEVEL != 0
|         || __GNU_MP_VERSION > 4
|         || (__GNU_MP_VERSION == 4 && __GNU_MP_VERSION_MINOR >= 3))
|       s << "." << __GNU_MP_VERSION_PATCHLEVEL;
|     header_version = s.str();
|   }
| 
|   std::string library_version = gmp_version;
| 
|   if (header_version != library_version) {
|     std::cerr
|       << "GMP header (gmpxx.h) and library (ligmpxx.*) version mismatch:\n"
|       << "header gives " << header_version << ";\n"
|       << "library gives " << library_version << "." << std::endl;
|     return 1;
|   }
| 
|   if (sizeof(mp_limb_t)*CHAR_BIT != BITS_PER_MP_LIMB
|       || BITS_PER_MP_LIMB != mp_bits_per_limb) {
|     std::cerr
|       << "GMP header (gmpxx.h) and library (ligmpxx.*) bits-per-limb mismatch:\n"
|       << "header gives " << BITS_PER_MP_LIMB << ";\n"
|       << "library gives " << mp_bits_per_limb << ".\n"
|       << "This probably means you are on a bi-arch system and\n"
|       << "you are compiling with the wrong header or linking with\n"
|       << "the wrong library." << std::endl;
|     return 1;
|   }
| 
|   mpz_class n("3141592653589793238462643383279502884");
|   return 0;
| }
| 
configure:10115: result: no
configure:10250: error: Cannot find GMP version 4.1.3 or higher.

这个主要原因是因为所使用的MinGW包含了gmp的动态链接库,同时MinGW自带的gmp的版本较低(根据config.log可以看出MinGW自带的版本是5.0.1),而链接到的头文件却是新版本的(5.0.4),同时用来测试gmp版本的程序加载了MinGW自带的gmp的库,进而造成了不一致性。

解决方法:把新编译出来的新版libgmp-10.dll复制到MinGW\bin替换MinGW自带的gmp库即可。

另外,从理论上来讲,修改PATH应该也是可以的。

  1. 本文目前尚无任何评论.