Building a shared library (dll) for MPFR

White, Jim (ITD) Jim.White@DEFRA.GSI.GOV.UK
Wed, 16 Jul 2003 14:10:19 +0100


A Win32 dll version of gmp is easily built on a PC
under MinGW, but the current build system does not 
allow for mpfr to be incorporated in the gmp dll. It
builds a static library (libmpfr.a) regardless of the
gmp build type.

MPFR is officially "still in development", so I imagine
that in the future the gmp build system will probably 
be upgraded to incorporate the mpfr entrypoints when
building gmp as a shared library.

But meanwhile, a separate Win32 dll for MPFR can easily be 
built (at least, by MinGW users!)


1. Build "libgmp-3.dll" 
=======================

In MinGW (MSYS shell emulator) a shared version of gmp
is built as follows (thanks to deltatrinity for this
method) :-

   ./configure --enable-shared --disable-static --build=$CPU-pc-mingw32 

where $CPU is your target cpu type (e.g. "i386", "pentium4", etc)


To get MPFR capability included you need an additional configure
option :-

   --enable-mpfr

After running configure, issue a "make" command and you will
get "libgmp-3.dll" created in directory ./libs. 

As I mentioned above, currently the mpfr entry points are NOT
included in libgmp-3.dll. The system simply builds a static 
library "libmpfr.a" in the ./mpfr directory.

We don't need "libmpfr.a" itself, but we'll use the compiled
object files that were used to build it, plus the gmp shared
library we've built, to create a shared "libmpfr.dll".



2. Build "libmpfr.dll" 
=======================

We build a shared version of MPFR as follows :-

   cd ../mpfr
   gcc -shared -o libmpfr.dll *.o ../.libs/libgmp-3.dll


This creates libmpfr.dll, which should be copied into the
same installation directory as libgmp-3.dll.


3. Warning to VB users
=======================

Like libgmp-3 itself, the libmpfr.dll uses "cdecl" calling
conventions so cannot be used directly from VB, but this
is not a major problem as a simple interlude dll can be
built to accept "stdcall" function calls from the application
and make the corresponding "cdecl" calls to libmpfr.dll.


Cheers

	Jim White
	Systems Programmer
	ITD(A)E, SPS Devt Team
	*	01483 403978
	*	Jim.White@defra.gsi.gov.uk
	H	A410, Epsom Road, Guildford GU12LD