Paul Zimmermann | 15 Jun 16:04 2010
Picon

MPFR under Windows

       Hi,

Brian Gladman helped us to update the MPFR INSTALL file concerning Windows.
However he could not really test the parts dealing with MinGW or Cygwin.
Thus we would be very grateful if somebody could check them, and send us
corrections if needed. In particular the file says:

> With gmp-4.1.3, the only remaining problem seems to be the "alloca" 
> calls...

is this still relevant with gmp-5.0.1?

And:

> For example under Win32, the following problem has been experienced with
> MPFR 2.4.0 RC1 and the MSVC runtime (msvcrt.dll):

does this problem still appear? (If so, it would be good to tell which version
of the MSVC runtime was used.)

I include the relevant portion of the new file below (beware, this differs
from what is shipped with MPFR 3.0.0).

Best regards,
Paul Zimmermann

##############################################################################

MPFR for use with 32-bit Windows Applications (win32)
=====================================================

There are several ways of building MPFR on Windows, the most appropriate
approach depending on how you intend to use the resulting libraries.

a. Using MinGW
==============

1 - We advise to use MinGW (http://www.mingw.org/), which is simpler and
    less demanding than Cygwin. Contrary to Cygwin, it also provides native
    Windows code. The binaries compiled with Cygwin require a dynamic
    library (cygwin.dll) to work; there is a Cygwin option -mno-cygwin to
    build native code, but it may require some non-portable tricks.

2 - If you just want to make a binary with gcc, there is nothing to do:
    GMP, MPFR and the program compile exactly as under Linux.
    But if you want to generate a library for MinGW from a Cygwin
    environment, you may need the -mno-cygwin gcc option (otherwise
    a typical error is _P_WAIT being undeclared).

3 - If you want to make libraries to work under another Windows compiler
    like Visual C / C++, you have two options.  Since the unix-like *.a
    library files are compatible with Windows *.lib files, you can simply
    rename all *.a libraries to *.lib.  The second option is to build
    MPFR with the Microsoft Visual Studio compiler to produce Windows
    libraries directly (Visual Studio build projects for MPFR are
    available at http://fp.gladman.plus.com/computing/gmp4win.htm).

    With gmp-4.1.3, the only remaining problem seems to be the "alloca" calls
    in GMP. Configuring GMP and MPFR with --enable-alloca=malloc-reentrant
    should work (if you build MPFR with GMP internal files).

    Or you could add the library
     "$MINGWIN$/lib/gcc-lib/mingw32/$VERSION$/libgcc.a"
    to your project: it contains all the extra-functions needed by a program
    compiled by gcc (division of 64-bit integer, bcopy, alloca...).
    Of course, include it if and only if your compiler is not gcc.

4 - On Windows32 / MinGW, if all the tests fail, try to run the test suite
    with "make check EXEEXT=".

5 - To avoid using the Microsoft runtime (which might not be conform to ISO C),
    you can use the MinGW runtime package (which is an integral part of MinGW).
    For example, with MinGW versions 3.15 and later you can get an
    ISO-compliant printf() if you compile your application with either
    '-ansi', '-posix' or '-D__USE_MINGW_ANSI_STDIO'. For example, you can
    compile and test MPFR with CC="gcc -D__USE_MINGW_ANSI_STDIO".

    For example under Win32, the following problem has been experienced with
    MPFR 2.4.0 RC1 and the MSVC runtime (msvcrt.dll):

       Error in mpfr_vsprintf (s, "%.*Zi, %R*e, %Lf%n", ...);
       expected: "00000010610209857723, -1.2345678875e+07, 0.032258"
       got:      "00000010610209857723, -1.2345678875e+07, -0.000000"
       FAIL: tsprintf.exe

    This error is due to the MSVC runtime not supporting the L length modifier
    for formatted output (e.g. printf with %Lf). You can check this with the
    following program:

       #include <stdio.h>
       int main (void)
       {
         long double d = 1. / 31.;
         printf ("%Lf\n", d);
         return 0;
       }

    The expected output is 0.032258.

    Note: The L modifier has been standard for a long time (it was added
    in ISO C89).

b. Using Cygwin
===============

This build should be similar to that for MinGW except that the resulting
library depends on the Cygwin DLL and cannot therefore be used with
Visual Studio as described above.

c. Using Visual C++ 2008/2010
=============================

Win32 versions of the MPFR library can be built using Microsoft Visual
C++ 2008 or 2010 using the build projects available here:

http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php

These build projects contain both win32 and x64 builds but the latter
will give errors if your version of Visual C++ lacks the 64-bit
compiler and tools.   The 32-bit build projects should however work
on Visual C++ 2008, Visual C++ Express 2008 (SP1), Visual C++ 2010
and Visual C++ Express 2010.

MPFR for use with 64-bit Windows Applications (x64)
===================================================

There are two ways of building MPFR for use with 64-bit Windows
applications.

a. Using MinGW64
================

The MinGW64 version of the GCC compiler is now available here:

http://sourceforge.net/projects/mingw-w64/

It can build both GMP and MPFR for 64-bit Windows applications.

b. Using Visual C++ 2008/2010
=============================

x64 versions of the MPFR library can be built using Microsoft Visual
C++ 2008 or 2010 using the build projects available here:

http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php

These build projects contain both win32 and x64 builds but the latter
can only be built if your version of Visual C++ contains the 64-bit
compiler and tools.  On Visual C++ 2008, the 64-bit tools are an
option during installation so if you don't have them you will need
to start the Visual Studio installer and add them to your IDE
configuration.  On Visual C++ 2010 they are installed by default.

As delivered, Visual C++ Express 2008 SP1 cannot build x64 projects
but the Windows SDK can be added to it to allow this. The IDE then
needs to be configured as described here:

http://msdn.microsoft.com/en-us/library/9yb4317s(VS.80).aspx

to allow x64 builds.

Visual C++ Express 2010 requires the Windows 7 SDK to be installed
in order to build x64 projects. This SDK is available here:

http://tinyurl.com/25zz8r6

In this case, once this SDK has been installed, Visual C++ Express 2010
will build x64 projects without further changes.


Gmane