I succeded to compile and test the mex module for Windows 7 x64 (Sp1) linking with the multithreded OpenBlas. In this way one can take advantage of the multicore architecture of the available CPU. For the Windows operating system the process is rather convoluted and delicate (one can easily get into the so called "dll hell" problem). The solution is indeed based on creating a dll file. I got it working following a script from Roland, so many thanks to him who pioneered a way to compile using Cygwin and gracefully shared his own script.
The idea is the following:
1) install Openblas and add its lib folder to the $Path$ Environment variable.
2) install Cygwin64 (the Devel package)
3) make sure you have SDK 7.1 installed along with Visual Studio 10.0 (it's free) and all the updates for Win7.
4) add to the $Path$ environment variable "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64"
5) find and copy the x64 version of IESHIMS.dll into a folder added to $Path$ environment variable. (I know, this is counterintuitive and seems esoteric but if you don't it may not work) To check that this is needed one can use "Dependency Walker".
6) open the Cygwin64 terminal and go to the "lbfgsb3.0_mex1.2" folder and make sure the "Lbfgsb.3.0" subfolder with all its files is inside (if not download it).
7) Type (or creat a .sh script to run at once):
x86_64-w64-mingw32-gfortran.exe -c -Wall -Wno-uninitialized lbfgsb.f linpack.f blas.f timer.f
echo EXPORTS > liblbfgsb.def
echo setulb_ >> liblbfgsb.def
echo _setulb_=setulb_ >> liblbfgsb.def
dlltool -D liblbfgsb.dll -d liblbfgsb.def -e liblbfgsb.o -l liblbfgsb.dll.a lbfgsb.o linpack.o blas.o timer.o
lib /def:liblbfgsb.def /machine:x64
x86_64-w64-mingw32-gfortran.exe -mdll -static-libgfortran -o liblbfgsb.dll liblbfgsb.o lbfgsb.o linpack.o timer.o blas.o
cp liblbfgsb.dll liblbfgsb.dll.a liblbfgsb.lib .
cp liblbfgsb.dll liblbfgsb.dll.a liblbfgsb.lib ..
cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libgcc_s_seh-1.dll ..
/cygdrive/c/Progra~1/MATLAB/R2013b/bin/mex.bat -O -largeArrayDims -UDEBUG lbfgsb_wrapper.c liblbfgsb.lib -lmex -lmx -lopenblas
8) Test example_NNLS.m
Dear Chenchen Tong,
I got the same error, when running compile_mex.m on Ubuntu 12.04, gcc-4.6 and MATLAB R2013a:
=== lbfgsb "driver1" test problem, 2D ===
`GFORTRAN_1.4' not found (required by
For me the problem was solved by running MATLAB with LD_PRELOAD and LD_LIBRARY_PATH, pointing to the system libraries:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libgfortran.so.3 LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu matlab
Could you please post detailed instructions for how to compile the lbfgsb_wrapper in Windows 7 64bit?
I was only able to compile in Linux and Mac OS X so far . I also linked with the OpenBlas library which is very fast ( if you have a multi-core cpu).
Thank you very much.
That's great it works! If you wouldn't mind, can you post detailed instructions here? I think many others would find them useful.
You're right about the typo in the nrhs. I'll fix that in the next update.
Right now, the gradient is necessary. The Python and R versions use large packages to get around this. They might have a finite-differences gradient approximation mode, but I suspect they are really doing automatic differentiation (the good news is that this is the exact gradient, no approximation. The bad news is that it can be sometimes slow). There are automatic differentiation packages for Matlab, but none that seem to be very "mature". So you could try some of those, but if you can work out an explicit function to compute the gradient, that is usually the simplest (no automatic differentiation packages to get working) and the fastest for computation.