Tuesday 5 March 2013

Compiling libgcrypt for win64

After a long search for how to compile libgcrypt for win64, i found a solution to do so, and here i would like to share it,

libgpg-error also needs to be build to successfully compile libgcrypt. Hence we also compile libgpg-error here.
Both the libraries can be downloaded from here.
Before compiling in 64 bit you will need to get familiar with few tools,
MinGW-64 and MYSYS: These are necessary to compile the libgcrypt library.

-------------------------------------------------------------------------------------------------------------------
R E Q U I R E D  T O O L S
-------------------------------------------------------------------------------------------------------------------

MinGW-w64

It is necessary to have mingw32 on the machine to sucessfullly compile libgcrypt.
MinGW-w64 provides GNU compiler collection (GCC) and GNu Binutils, for the use in the development of native microsoft windows applicaiton.

Download Site : http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Automated%20Builds/

Step 1:
Download the zip version of the file, for windows, and not the .tar.bz2 version.
I had downloaded "mingw-w64-bin_i686-mingw_20111220.zip".

Step 2:
Extract it to a folder, i had extracted the file to "c:\mingw".
-------------------------------------------------------------------------------------------------------------------

MSYS

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present.

Download Site: http://sourceforge.net/projects/mingw-w64/files/External%20binary%20packages%20%28Win64%20hosted%29/MSYS%20%2832-bit%29/

Though i will refer the installation steps here, you can find the installation inforamtion at the below link. http://sourceforge.net/apps/trac/mingw-w64/wiki/MSYS

Step 1: Download the MSYS-xxxxxxxx.zip file, do not download the source code.
I had downloaded the MSYS-20111123.zip file.
Step 2: Extract the file, i had extracted the file in "c:\msys".
Step 3: Go to "c:\mysys" and doubleclick msys.bat file.
Step 4: Type: sh /postinstall/pi.sh
It will ask do you want to continue with post install , press 'y' and then 'enter' key.
Then it will ask, "Do you have MinGW installed?", press 'n' and the 'enter' key.
Press "ENTER" to continue the process.
Step 5: Type: mount (path to mingw) /mingw
I had typed, mount c:\\mingw /mingw

This will mount our mingw directory at /mingw, the path variable is already set to /mingw/bin
just make sure you have the binaries in "c:\mingw\bin"

-------------------------------------------------------------------------------------------------------------------
C O M P I L A T I O N  S T E P S
-------------------------------------------------------------------------------------------------------------------

First we will compile libgpg-error.

Step 1: Extract the downloaded libgpg-error library to a folder.
Step 2: Open the MSYS terminal ("c:\\msys\msys.bat") and use cd command to go to the directory where you extracted it.
Step 3: ./configure --host=x86_64-w64-mingw32 --prefix=path_to_installation directory
I had used:
./configure --host=x86_64-w64-mingw32 --prefix=/home/newUser/installDir/
After sucessful compilation, we find the binaries in the directory specified by --prefix.

Step 4: Now type: make install
This should make the library and put it in the folder specified by --prefix specified in the ./configure
-------------------------------------------------------------------------------------------------------------------

Compiling libgcrypt:

Step 1: Extract the downloaded libgcrypt library
Step 2: Open the MSYS terminal ("c:\\msys\msys.bat") and cd to where you extracted it.
Step 3: ./configure --host=x86_64-w64-mingw32 --prefix=<whatever> --with-gpg-error-prefix=<dir where you installed libgpg-error> --disable-asm
I had used:
./configure --host=x86_64-w64-mingw32 --prefix=/home/newUser/installDir/ --disable-asm

After sucessful compilation, we find the binaries in the directory specified by –prefix.

Step 4: Now type: make install
This should make the library and put it in the folder specified by --prefix specified in the ./configure
Note that i have used the same installation directory to install libgpg-error and libgcrypt.

I have yet not successfully tested each functionality of the library, but i hope it works fine, and note that after compiling libgcrypt library you will find a .dll.a file in lib folder which is present in the directory where you installed the library (the path you had provided to --prefix option while running configure command)

This .dll.a is actually the .lib file of the dynamic library.
The installation directory/bin will contain the .dll files of the library.
-------------------------------------------------------------------------------------------------------------------

Explore more, learn more.... ;)

3 comments:

  1. After i ignored errors with installing libgpg-error i also had to supply the following options to have libgcrypt make:

    make CFLAGS="-DNO_ASM"

    ReplyDelete
    Replies
    1. Hi Christopher,
      Thanks for your inputs. :)

      Delete
  2. I am wondering how to compile for 32-bit only Windows...

    ReplyDelete