win2k and build for GMP

delta trinity
Sat, 21 Jun 2003 23:14:24 -0400

This is a multi-part message in MIME format.

Content-Type: text/plain; format=flowed

>From: "Rajeev Sangra" <>
>To: <>
>Subject: win2k and build for GMP
>Date: Sat, 21 Jun 2003 17:07:34 -0700
>I read the manual for the GMP and trying to set up an environment for 
>building  a Windows DLL on my machine ( Win2K and Microsoft VC++ 6.0)
>I am not very familiar with the unix flavour and so is with gnu libraries
>I would appreciate if you could share the steps i need to perfom to setup 
>the environment on my machine

Well, the easiest way would be to take the DLL already made.  For now, my 
ftp site is down (at least for the month of june, till I move in to my new 

To compile GMP under Windows, I used Cygwin as a Unix shell emulator.  And I 
compiled with MinGW, so not to have GMP DLL linked to CYGWIN1.DLL but rather 
to the native MSVCRT.DLL.  I don't know if you can do it without CYGWIN, I 
heared of people who did it.  For me, I didn't try because at the time, back 
when I was in the trial and error phase :) , I started with Cygwin.

I compiled a .txt at the time.  I don't know if it's up to date but I've 
attached it to this mail.

So, you'll have to do a bit of unix flavour things like running shell script 
('./configure').  Don't worry, at the time, I probably didn't had much 
knowledge of Unix too, and I figured it out (with a lot of time and a lot of 
cola cans!).

Add photos to your messages with MSN 8. Get 2 months FREE*.

Content-Type: text/plain; name="GMPOnWindowsDLL-Steps.txt"; format=flowed
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="GMPOnWindowsDLL-Steps.txt"

I finally arrived at something.  Let's call the DLL we want to make, the 
'Target DLL'.
Here's how I done it.  For the other of you who are trying to do the same.

The basic idea was to use CYGWIN environment under Windows but once the DLL 
is compiled, not to have to use CYGWIN1.DLL but the native Windows DLL.  I 
had problems using CYGWIN1.DLL in the calloc function (crash).  To do this, 
you must not compile under cygwin but rather, under MinGW.  There may be 
other solutions but I used thos one and it worked so...

You will need the latest CYGWIN tools (
You will also need MinGW tools (
And, finally, GMP (I used 4.0.1)

I installed CYGWIN (running setup, install base files and 'make') in, let's 
say, c:\cygwin.

Then, I installed MinGW .tar in c:\cygwin\bin\MinGW and untar from there.  
Then, add \bin\MinGW\bin at the beginning of the PATH (so the gcc and 
library from MinGW are used instead of cygwin).

Once this is done, you're almost ready to compile but there's a few pitfall. 
  If someone can correct this in GMP (or take the limitation into account in 
the scripts), please do so.


To make a Windows DLL from GMP, you need to tell 'configure' tool the 
'--enable-shared --disable-static'.

You also want not to use cygwin core (cygwin1.dll) so you also add 
'CFLAGS=-mno-cygwin'.  But, setting CFLAG overwite default settings so you 
need to set CFLAGS with the original parameters 'CFLAGS="-mno-cygwin -g -O2 
-fomit-frame-pointer -mcpu=pentiumpro -march=i486".  Note that some of the 
parameters may be different.  To be sure, just run 'configure' once without 
the CFLAGS and check the screen lon or a makefile for the CFLAGS default.

You're compiling under MinGW.  MinGW and Cygwin handle things differently in 
the final target dll so, you have to tell that you want to build using mingw 
or else, you'll end up in an unloadable target DLL.  So, you alse tell to 
'build' (maybe just host would suffice, I didn't try) using mingw 
('-build=pentium2-pc-mingw32', substitute processor four anything you may 
have).  You may also set host to cross-compile although I didn't try 
('-host=*-pc-mingw32' where * is the CPU under which the target DLL will 
run).  Ex, I compile using my P2 but want to run GMP un a fast P4 or K7, 
'-build=pentium2-pc-mingw32 -host=pentium4-pc-mingw32'.

That's almost it but then, one last pitfall, cygwin come with a 'make' 
utility, MinGW too.  But, 'configure' just crash using the MinGW 'make' :( 
so either someone would need find what is needed to be added to 'configure' 
or just rename MinGW 'make' (/bin/MinGW/bin/make.exe' to '_make.exe'.  So, 
this way, cygwin 'make' is used.  Don't worry, the make utility don't affect 
target DLL.

Last pitfall, running 'configure' create some link to many of the used files 
for specified target.  Thise links realy are Windows shortcuts (.lnk).  
Cygwin come with 'gcc' (if you install it) and MinGW too.  Both are nice but 
MinGW doesn't handle Windows shortcut.  That's bad I know.  If you try with 
windows shortcut (ex, 'configure' put a file in gmp root called 
'gmp-mparam.h' for which the other .h files rely on.  But it's realy 
'gmp-mparam.h.lnk', a Windows shortcut.  MinGW gcc at compile time complain 
about not finding those .h files :(   To avoid this, you realy need 
'configure' to create hard copy of the files, not shortcut.  In 'configure', 
toward the end, there's some lines where you read:

# Make a symlink if possible; otherwise try a hard link.
ln -s $ac_rel_source $ac_dest 2>/dev/null ||
    ln $srcdir/$ac_source $ac_dest ||

Change this to:
# Make a symlink if possible; otherwise try a hard link.
# ln -s $ac_rel_source $ac_dest 2>/dev/null ||
    ln $srcdir/$ac_source $ac_dest ||
(Add a comment on first 'ln -s' so hard link (copy) are created instead of 
symbolic link).

Probably something better would be to add a case for 'mingw', feel free to 
do so.

So, to resume:
- Rename MinGW 'make.exe' to '_make.exe'.
- edit 'configure', comment the 'ln -s ...' line.
- run ./configure --enable-shared --disable-static 
-build=pentium2-pc-mingw32 CFLAGS="-mno-cygwin -g -O2 -fomit-frame-pointer 
-mcpu=pentiumpro -march=i486"

- Once configuration is done, just type 'make' (which will also use cygwin 
'make.exe' but here again, it does not affect target dll).
- If you want to compile faster, optionally, you can instead run 'make -j 5' 
(run 5 jobs at the same time).

- Resulting from this is a few files with one called 'LIBGMP-3.DLL', the 
target DLL.
- Take it, along with the 'gmp.h' in the GMP root directory to make your 
windows apps.  Possibly 'gmpxx.h' for C++ implementations, I didn't try.
- Looking at target DLL (with a file dumper like TDUMP), you can see that 
the DLL import functions only from 'MSVCRT.DLL', the native MS Windows dll 
and no more 'CYGWIN1.DLL'. :)

That's it...