As I'm trying to compile the mex file on a W7 x64 with Matlab R2013a, I follow the tutorial of Daniel, and I would need some specification (thanks by the way for sharing this) :
- the line "lib /def:liblbfgsb.def /machine:x64" gives me
$ lib /def:liblbfgsb.def /machine:x64
-bash: lib: command not found
-I tried to run the compilation anyway, and it gives me this :
$ mex.bat -O -largeArrayDims -UDEBUG lbfgsb_wrapper.c liblbfgsb.lib -lmex -lmx -lopenblas
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: 'lbfgsb_wrapper.c' not found.
I'm not a great expert on bash's command, and I can't figure out what's the real problem behind these.
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.