Memo‎ > ‎

Build ARPACK on Windows for Visual Studio

posted Jan 19, 2015, 11:33 PM by Teng-Yok Lee   [ updated Jan 21, 2015, 7:27 AM ]
This is a revision of Jernej Barbic's steps to build ARPACK for Visual Studio. The original steps are in the URL below:

http://www-bcf.usc.edu/~jbarbic/arpack.html

I met issues when executing step 3 so I decide to put my modified procedure here. For 32-bit, you can try both gfortran or g77. For 64-bit, only gfortran can work.

My recommendation is to use the MinGW64 in CYGWIN64.

Use gfortran (Win32)

  1. Modify ARmake.inc in the source code root. I extracted the source code of ARPACK to D:\src\ARPACK. Also I cannot find f77 in the latest MinGW so I used gfortran instead. Thus the following variables should be changed accordingly:
    home = /d/src/ARPACK
    PLAT = win32
    FC      = gfortran
    FFLAGS    = -O
  2. Open a MSYS window and:
    cd /d/src/ARPACK.
  3. Compile the .f to .o:
    make lib
  4. Wrap the *.o to .dll. I need to add the library gfortran:
    dllwrap --export-all-symbols BLAS/*.o LAPACK/*.o SRC/*.o UTIL/*.o -lg2c -lgfortran --output-def arpack_win32.def -o arpack_win32.dll
  5. Open a Visual Studio Command Prompt and:
    cd d:\src\ARPACK
  6. Generate the library:
    lib.exe /machine:i386 /def:arpack_win32.def

Use g77 (Win32)

  1. Modify ARmake.inc in the source code root. I extracted the source code of ARPACK to D:\src\ARPACK. Also I cannot find f77 in the latest MinGW so I used gfortran instead. Thus the following variables should be changed accordingly:
    home = /d/src/ARPACK
    PLAT = win32
    FC      = g77
    FFLAGS    = -O
  2. Open a MSYS window and:
    cd /d/src/ARPACK.
  3. Compile the .f to .o:
    make lib
  4. Wrap the *.o to .dll.
    dllwrap --export-all-symbols BLAS/*.o LAPACK/*.o SRC/*.o UTIL/*.o -lg2c --output-def arpack_win32.def -o arpack_win32.dll
  5. Open a Visual Studio Command Prompt and:
    cd d:\src\ARPACK
  6. Generate the library:
    lib.exe /machine:i386 /def:arpack_win32.def

Use gfortran (Win 64) in MSYS

Before the procedure, install MinGW 64. In my case, it is installed to C:\Program Files (x86)\mingw-w64, and gfortran.exe is in C:\Program Files (x86)\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev1\mingw32\bin.
  1. Modify ARmake.inc in the source code root. I extracted the source code of ARPACK to D:\src\ARPACK. Also I cannot find f77 in the latest MinGW so I used gfortran instead. Thus the following variables should be changed accordingly:
    home = /d/src/ARPACK
    PLAT = x64
    FC = /c/Program\ Files\ \(x86\)/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev1/mingw32/bin/gfortran.exe
    FFLAGS    = -O
    RANLIB = /c/Program\ Files\ \(x86\)/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev1/mingw32/bin/ranlib.exe

  2. Open a MSYS window and:
    cd /d/src/ARPACK
  3. Extend PATH:
    export PATH=$PATH:/c/Program\ Files\ \(x86\)/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev1/mingw32/opt/bin
  4. Change UTIL/second. Remove the sentence: EXTERNAL           ETIME.
  5. Compile the .f to .o:
    make lib
  6. Wrap the *.o to .dll:
    /c/Program\ Files\ \(x86\)/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev1/mingw32/bin/dllwrap.exe --export-all-symbols BLAS/*.o LAPACK/*.o SRC/*.o UTIL/*.o -lgfortran --output-def arpack_x64.def -o arpack_x64.dll
  7. Open a Visual Studio (64-bit) Command Prompt and:
    cd d:\src\ARPACK
  8. Generate the library:
    lib.exe /machine:X64 /def:arpack_x64.def

Use gfortran (Win 64) in cygwin

Later I found later MinGW is also available in CYGWIN, which make the commands shorter.

Before the procedure, install mingw64-x86_64-gcc in CYGWIN 64.

  1. Modify ARmake.inc in the source code root. I extracted the source code of ARPACK to D:\src\ARPACK. Also I cannot find f77 in the latest MinGW so I used gfortran instead. Thus the following variables should be changed accordingly:
    home = /cygdrive/d/src/ARPACK
    PLAT = x64
    FC = /usr/bin/x86_64-w64-mingw32-gfortran.exe
    FFLAGS    = -O
    RANLIB = /usr/bin/x86_64-w64-mingw32-ranlib.exe

  2. Open a MSYS window and:
    cd /cygdrive/d/src/ARPACK
  3. Change UTIL/second. Remove the sentence: EXTERNAL           ETIME.
  4. Compile the .f to .o:
    make lib
  5. Wrap the *.o to .dll:
    /usr/bin/x86_64-w64-mingw32-dllwrap.exe --export-all-symbols BLAS/*.o LAPACK/*.o SRC/*.o UTIL/*.o -lm -lgfortran --output-def arpack_x64.def -o arpack_x64.dll
  6. Open a Visual Studio (64-bit) Command Prompt and:
    cd d:\src\ARPACK
  7. Generate the library:
    lib.exe /machine:X64 /def:arpack_x64.def

Link the lib

After building .lib and .dll, adding the directories of related dll. to your path. For CYGWIN, the path is

C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin

For MinGW, it should be the path to the 64-bit.

If the .dll does not match to the linked library, it might show error The application was unable to start correctly (0xc000007b). I saw it when my system had both 32-bit and 64-bit versions of MinGW. After I uninstalled both and just kept CYGWIN 64, the problem was solved.

References

  1. External issue of etime: https://gcc.gnu.org/ml/fortran/2007-03/msg00305.html
  2. Use CYGWIN and MinGW64 to build Visual Studio libraries: https://github.com/arrayfire/arrayfire/wiki/CBLAS-for-Windows
  3. Cannot start my application: http://stackoverflow.com/questions/25124182/mingw-gcc-the-application-was-unable-to-start-correctly-0xc000007b

Comments