473,911 Members | 5,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setup write compile and run GMP progs in cygwin

dot
I spent a few headache filled days trying to use GMP on windows
(XP pro)
I finally got it to work and since I found little help on the Web
I thought someone might find what i did useful.

Creating an environment suitable for GMP programming.

1) Create 'cygwin' environment (see below)

2)add GMP to the cygwin directory (see below)
"
GMP Install Instruction for Windows Platform

Currently Core Library (from v1.4) uses GNU Multiple Precision Arithmetic Library (GMP) as its low level big number package. GMP is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating point numbers. As GMP was originally designed to work under Unix platform, there is little information about how to compile and install under Windows platform. I wrote this page to help you simplify installation.

While there are many C/C++ compilers available under Windows Platform, I will only focus on the following 4 compilers/environments: Cygwin GCC, MinGW GCC, Visual C++ 6.0 and .Net which are freely available or widely used. If you have experiences on other compilers, please let me know.

To help your development, GMP 4.1 source distribution and pre-compiled libraries for these environments are provided here for download. It should work for Pentium III or above.

* GMP 4.1 source distribution: gmp-4.1.tar.gz
* static GMP library and header file for Cygwin: gmp-static-cygwin-4.1.tar.gz
* static GMP library and header file for MinGW: gmp-static-mingw-4.1.tar.gz
* static GMP library and header file for Visual C++: gmp-static-vc-4.1.2.zip
* dynamic GMP library and header file for Cygwin: gmp-dynamic-cygwin-4.1.tar.gz
* dynamic GMP library and header file for MinGW: gmp-dynamic-mingw-4.1.tar.gz
* dynamic GMP library and header file for Visual C++: gmp-dynamic-vc-4.1.2.zip
* patches and project files

In the following, I assume that you want to download GMP to ${gmp_download} , build GMP at ${gmp_build}, and install GMP to ${gmp_install}
Cygwin & MinGW (Building static GMP library)

* Cygwin is a free Unix-like environment, developed by Red Hat, for Windows. This environment is very stable and has no hidden overhead (unlike some other operating systems). All the common tools and functionality you expect in a Unix environment are available, including "make", "gcc", "gdb", etc. Installing GMP under Cygwin is very similar with the installations under other Unix platforms, e.g. Solaris and Linux, except that you cannot build static and shared libraries at the same time. Here is the detail instruction:
1. Install latest Cygwin. Make sure that you choose to install "gcc", "m4" and "make" since the default installation doesn't include them.
2. Download latest GMP from GNU MP to ${gmp_download} .
3. Run "Cygwin Bash", unzip and untar GMP into ${gmp_build} using following command:

cd ${gmp_build}
tar xzvf ${gmp_download}/gmp-x.x.x.tar.gz

4. Configure GMP for compilation:

cd gmp-x.x.x
./configure --prefix=${gmp_in stall}

5. Build GMP:

make

6. Install GMP header files and lib files:

make install

* MinGW is a collection of header files and import libraries combined with GNU toolsets that allow one to use GCC and produce native Win32 programs that do not rely on any 3rd-party DLLs, while the programs compiled under cygwin need a DLL named "cygwin1.dl l". To provide a similar environment like cygwin, MSYS(Minimal SYStem) was created. If you have installed MSYS Version 1.0.7 or above, then the installation is as same as above cygwin environment:
1. Install latest MinGW first, and then MSYS.
2. Download latest GMP from GNU MP to ${gmp_download} .
3. Run "MSYS", unzip and untar GMP into ${gmp_build} using following command:

cd ${gmp_build}
tar xzvf ${gmp_download}/gmp-x.x.x.tar.gz

4. Configure GMP for compilation:

cd gmp-x.x.x
./configure --prefix=${gmp_in stall}

5. Build GMP:

make

6. Install GMP header files and lib files:

make install

For MSYS's earlier version, "make.exe" and "ranlib.exe " in MSYS will fail to process GMP's configure script. To fix this, you can download "make.exe" and "ranlib.exe " to overwrite your old version, then follow step 2-6.
* For those who would like to use the Cygwin environment for development MinGW, you can follow these steps:
1. Install latest Cygwin. Make sure that you choose to install "gcc", "m4" and "make" since the default installation doesn't include them.
2. Install latest MinGW into ${mingw}.
3. (For MinGW 2.0 earlier only) Rename MinGW's "make.exe" (${mingw}/bin/make.exe) to "mingw32-make.exe".
4. Add ${mingw}/bin at the beginning of the environment variable PATH.

export PATH=${mingw}/bin:$PATH (for bash, sh)

or

setenv PATH ${mingw}/bin:$PATH (for csh, tcsh)

5. Download latest GMP from GNU MP to ${gmp_download} .
6. Run "Cygwin Bash", unzip and untar GMP into ${gmp_build} using following command:

cd ${gmp_build}
tar xzvf ${gmp_download}/gmp-x.x.x.tar.gz

7. Modify the "configure" script in GMP, change these lines (toward the end)

# 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 ||

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 are created instead of symbolic link)
8. Configure GMP for compilation:

cd gmp-x.x.x
./configure --build=pentium3-pc-mingw32 --prefix=${gmp_in stall}

(replace "pentium3-pc" by your CPU type)
9. Build GMP:

make

10. Install GMP header files and lib files:

make install

Cygwin & MinGW (Building dynamic GMP library)

As I mentioned above, GMP cannot build static and shared libraries at the same time and it will only build static library by default. To use dynamic library, i.e DLL under windows platform, you need to add the options "--disable-static --enable-shared" when you configure GMP, i.e. run this command:

./configure --prefix=${gmp_in stall} --disable-static --enable-shared

A windows DLL "cyggmp-3.dll" (Cygwin) or "libgmp-3.dll" (MinGW) will be generated and you can link it with your executable programs as usual under Cygwin & MinGW except that when you run them, you have put these DLLs in some path which is listed in environment variable $PATH.

To ensure that these DLLs can be called by a Microsoft Visual C++ program, you must generate an import library (.lib) for them, using Microsoft LIB tool:

cd gmp-x.x.x/.libs
lib /machine:i386 /def:cyggmp-3.dll-def (for Cygwin)

or
lib /machine:i386 /def:libgmp-3.dll-def (for MinGW)

Visual C++ 6.0 & Visual C++ .Net

In Core Library distribution, we provide patch files for building GMP library under Visual C++:

1. Download latest GMP and unzip to ${gmp_build}
2. Copy all files under patches/4.1-static (or patches/4.1-dynamic for building DLL) to ${gmp_build}
3. Open gmp.dsw (gmp.vcproj for VC++.Net) to build GMP
4. After building, you can use gmp.h, lib/gmp.lib, lib/gmpDebug.lib to build your GMP application. (If you build GMP DLL, then you need gmp.dll or gmpDebug.dll for runing your application.)

Enjoy!

--Zilin Du (zilin "at" cs.nyu.edu)
Last Update: Jan 12, 2006
"


(the ellipsis ... means whatever drive, for most it will be C:)
The GMP tarball was copied to .../cygwin/gmp_download/ which in cygwin
bash is /gmp_download/
The GMP tarball was uncompressed to .../cygwin/gmp_build/ which in
cygwin bash is /gmp_build/
GMP was installed to .../cygwin/gmp_install/ which in cygwin bash is
/gmp_install/
as per instructions above.

3) Programs are written with the #include <gmp.h at the top of the
program source file.

e.g.
---------------------------------------------------------------------------------
/*************** *************** *************** ******
m take n
*************** *************** *************** *******/
#include <stdlib.h>
#include <stdio.h>
#include <gmp.h>
char *progname;
void print_usage_and _exit ()
{
fprintf (stderr, "usage: %s m n \n", progname);
exit (-1);
}

int main(int argc, char *argv[])
{
mpz_t a,b,c,i,j,k,m,n ;
unsigned int x;

progname = argv[0];
if (argc < 2)
print_usage_and _exit ();

mpz_init(a);
mpz_init(b);
mpz_init(c);
mpz_init(i);
mpz_init(j);
mpz_init(k);
mpz_init(m);
mpz_init(n);

if (mpz_set_str (m, argv[1], 10) != 0)
print_usage_and _exit ();
gmp_printf ("%Zd \n", m);
x = atoi(argv[2]);
printf ("%u \n", x);
mpz_bin_ui(c,m, x);
gmp_printf ("%Zd take %u = %Zd \n", m, x, c);
exit(0);
}
---------------------------------------------------------------------------------------

4) Compile the program with
gcc inprogname.c -o outprogname -L/gmp_install/lib -lgmp

This will result in executable code named outprogname.exe
This program can be run within the cygwin bash environment as
../outprogname.exe

(inprogname and outprogname are any names you assign your source and
target)

5) To run the program in windows, or the DOS box, copy cygwin1.dll from
/usr/bin/ to the
directory holding the executable (or include in the PATH env
variable (i think))
and run the program without the .exe extention.

---done---
....al
Dec 12 '07 #1
0 3326

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4338
by: DvDmanDT | last post by:
Hello, I have an intresting problem: I want to let users upload sourcecode and then compile it using my cygwin gcc... But one thing at a time... I can't get that gcc to execute... shell_exec("gcc temp.c"); # Doesn't work as that will use MinGW shell_exec("D:\\cygwin\\bin\\gcc.exe temp.c"); /* Gives some error about dll stuff (procedure not found I think)*/ So my next though was to open "bash.exe --login -I" and fwrite the commands......
1
1892
by: Mike Bates | last post by:
I'm trying to add the pymedia (http://pymedia.sourceforge.net/) module to my python installation. Unfortunetly I'm using windows XP, so I'm trying to do it using cygwin. When I type "setup.py build" or "python setup.py build" or "python.setup.py install" I get normal compilation messages and then it errors with this: In file included from video/libavcodec/common.h:26 from video/libavcodec/avcodec.h:14 from...
0
1713
by: Zhuanshi He | last post by:
I try to compile ScientificPython-2.4.9 (http://starship.python.net/~hinsen/ScientificPython/) under Windows XP cygwin environment using python 2.3.3 ,and gcc (GCC) 3.3.3 (cygwin special). The information shows as follows: ---------------------------------------------------------- Using netCDF installation in /usr/local running build
18
4906
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
16
10071
by: Weasel | last post by:
What do i use to compile , and basically program in windows? Since at home i use linux, but at school they dont have linux... what can i use?
12
3320
by: JS | last post by:
I use winXP and have installed Cygwin. I use Dev-C++ and the Cygwin compiler, but for some reason I can't compile this code: #include <setjmp.h> #include <stdio.h> #include <stdlib.h> typedef int othread_t;
0
962
by: AIM | last post by:
Hi all, I have a general question and some advice is needed. Over time, I am running into python modules with setups that are just made for linux/unix. I have python installed on windows. To get these modules into windows, should I do the following?
2
2530
by: James Calivar | last post by:
Hi, I'm trying to compile PHP v5.1.6 under Windows XP using cygwin. I get the following error when I run ./configure. Can anyone help please? $ ./configure loading cache ./config.cache checking for Cygwin environment... yes checking for mingw32 environment... no
2
6671
myusernotyours
by: myusernotyours | last post by:
Hi All, Am working on a Java application in which I have to use the JNI to Interface with some native code for both windows and unix. Am using netbeans IDE with the C/C++ pack installed. Am also using Cygwin as my compiler (gcc), this is ostensibly because I hope this compiler will also compile the unix native libraries since I don't have a Linux installation. (I am working on a personal project from the office and can't get linux installed)....
0
10038
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9879
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11057
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8099
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7250
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
4341
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.