% This script gives instructions to compile lbfgsb with MatLab on Windows % The source of the code is provided by Peter CARBONETTO % http://www.cs.ubc.ca/~pcarbo/lbfgsb-for-matlab.html % % The tools used here are MatLab, GNUMEX and MinGW % % Guillaume JACQUENOT % guillaume dot jacquenot at gmail dot com % 2009 03 24 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % INSTRUCTIONS % 0) Install GNUMEX and MinGW % GNUMEX is used to generate script files that will contain instructions % for MINGW compilers. % GNUMEX can be found at the following adress % http://gnumex.sourceforge.net/ % If you do not know GNUMEX, try to run examples before trying to % compile lbfgsb % % MINGW stands for MINimum GNU for Windows, it is the port of the GNU % Compiler Collection (GCC), and GNU Binutils for Windows % It is used to compile and link the dll % % 1) Generate two script files to compile C and Fortran files % 1a) mexopts.bat for C % Run GNUMEX and asks for language C/C++ % Don't forget to set the correct MINGW path (c:\mingw for me) % Saves the results in mexopts.bat % 1b) mexopts_fortran.bat % Run GNUMEX and asks for language fortran77 % Saves the results in mexopts_fortran.bat % % 2) Modify the generated file script mexopts.bat % Set the correct programming in mexopts.bat: c++ % "set GM_MEXLANG=c++" % To avoid linkage problems, I also manually set the compiler % "set COMPILER=g++" % I therefore delete the additional option "-x c++" % "set CPPCOMPFLAGS=%COMPFLAGS% -x c++" % becomes % "set CPPCOMPFLAGS=%COMPFLAGS%" % % I also add the g2c library in the mexopts.bat for the linkage with % fortran objects % "set GM_ADD_LIBS=-lg2c -llibmx -llibmex -llibmat" % % 3) Modify the generated file mexopts_fortran.bat % I replaced compilation flags provided by the generated file % mexopts_fortran.bat % Originally, these options looked like something like this % "set COMPFLAGS=-c -DMATLAB_MEX_FILE -fcase-upper -mrtd -fno-underscoring" % I set these flags to % "set COMPFLAGS=-c -DMATLAB_MEX_FILE -mrtd -fexceptions" % % The header of my script files (.bat) and my configuration are given at % the end of this file % % 4) Perform compilation % Here are the commands I used to compile lbfgsb % I assume the source code and the script files are in the same directory % % I had to add the -g option to have the program worked. % I don't understand why % Option -g: Build an executable with debugging symbols included. mex -v -g -c -f mexopts_fortran.bat solver.f mex -v -g -c -f mexopts.bat arrayofmatrices.cpp mex -v -g -c -f mexopts.bat lbfgsb.cpp mex -v -g -c -f mexopts.bat matlabexception.cpp mex -v -g -c -f mexopts.bat matlabmatrix.cpp mex -v -g -c -f mexopts.bat matlabprogram.cpp mex -v -g -c -f mexopts.bat matlabscalar.cpp mex -v -g -c -f mexopts.bat matlabstring.cpp mex -v -g -c -f mexopts.bat program.cpp mex -v -g -f mexopts.bat -output lbfgsb *.obj delete *.obj % List of generated obj % arrayofmatrices.obj lbfgsb.obj matlabexception.obj \ % matlabmatrix.obj matlabprogram.obj matlabscalar.obj \ % matlabstring.obj program.obj solver.obj % % Have fun. % Run the example examplehs038 to test the compilation % % You should see something like that % % 1 573 % 2 393 % 3 132 % 4 11.5 % 5 1.48 % 6 1.12 % 7 0.984 % 8 0.305 % 9 0.0847 % 10 0.0101 % 11 0.000123 % 12 0.000113 % 13 0.000113 % 14 0.000112 % 15 0.000109 % 16 9.75e-005 % 17 7.93e-005 % 18 7.17e-005 % 19 3.55e-005 % 20 1.46e-005 % 21 1.71e-006 % 22 1.94e-007 % 23 1.47e-007 % 24 8.84e-010 % 25 2e-011 % 26 2.21e-012 % 27 7.16e-014 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % MY CONFIGURATION % Windows XP 32 bits % Matlab 7.0 % MINGW 1.0 % GNUMEX 2.01 % % I guess with Windows Vista, you will have to change the scripts generated % by the GNUMEX tool. % % Mexopts_fortran.bat header % rem D:\GJ\Outils_resolutions\GNUMEX\mexopts_fortran.bat % rem Generated by gnumex.m script in d:\gj\OUTILS~1\gnumex % rem gnumex version: 2.01 % rem Compile and link options used for building MEX etc files with % rem the Mingw/Cygwin tools. Options here are: % rem Gnumex, version 2.01 % rem MinGW linking % rem Mex (*.dll) creation % rem Libraries regenerated now % rem Language: Fortran 77 % rem Optimization level: -O3 (full optimization) % rem Matlab version 7 % rem % Mexopts.bat header % rem D:\GJ\Outils_resolutions\GNUMEX\mexopts.bat % rem Generated by gnumex.m script in d:\gj\OUTILS~1\gnumex % rem gnumex version: 2.01 % rem Compile and link options used for building MEX etc files with % rem the Mingw/Cygwin tools. Options here are: % rem Gnumex, version 2.01 % rem MinGW linking % rem Mex (*.dll) creation % rem Libraries regenerated now % rem Language: C / C++ % rem Optimization level: -O3 (full optimization) % rem Matlab version 7 %