pcarbo / lbfgsb-matlab

A MATLAB interface for L-BFGS-B
GNU General Public License v3.0
51 stars 25 forks source link

Simple compilation procedure with MATLAB R2014a #2

Closed nolyn closed 10 years ago

nolyn commented 10 years ago

Hi,

with my MATLAB version (R2014a) it was not possible to compile lbfgsb using:

mex -output lbfgsb *.cpp solver.f Error using mex Cannot compile both C++ and FORTRAN source files in a single call to MEX.

Spending the better half of a day I figured out I can compile it by first compiling the fortran files to object files and linking them to the cpp files with a second run of mex:

mkdir objfiles mex -c -outdir objfiles/ solver30.f blas.f linpack.f timer.f mex -lgfortran -output lbfgsb *.cpp objfiles/blas.o objfiles/linpack.o objfiles/solver30.o objfiles/timer.o rmdir('objfiles','s')

I tested that it works with examplehs038.m

pcarbo commented 10 years ago

Hi,

Compiling these MEX files is notoriously difficult, especially when combining Fortran and C++ code. Unfortunately, developing an install script that works for all computers is beyond my capabilities.

I'm glad to hear that you eventually found a solution. I will include your suggestion in the README file in case anyone else encounters a similar problem.

Thanks again for your feedback. Peter

chandreshiit commented 8 years ago

Hi,

As a shortcut to compile and use lbfgsb, here is what I did to compile your code on linux terminal.

First compile .f files with ' gfortran -c -fPIC solver30.f linpack.f timer.f blas.f ' Next compile all .cpp files with 'g++ -c -fPIC .cpp -I. ' Now combine the two .o files with ' g++ -shared -Wl,--version-script,"/usr/local/MATLAB/R2014b/extern/lib/glnxa64/mexFunction.map" *.o -lmx -lmex -lmat -lm -lgfortran -o lbfgsb.mexa64 ' Make sure that mexFunction.map has correct path. That hack worked for me.

pcarbo commented 8 years ago

Nice! That's a great tip. Thanks for sharing.

emadenany commented 4 years ago

Hi,

Using the command: mex -c -outdir objfiles/ solver_3_0.f blas.f linpack.f timer.f

gives the following error: Error using mex No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.

I used this: mex -setup C++ MEX configured to use 'MinGW64 Compiler (C++)' for C++ language compilation.

and also

mex -setup Fortran and got Error using mex No supported compiler was found. For options, visit https://www.mathworks.com/support/compilers.

Could you please help how to solve this issue?

I am using trial Matlab 2020a.

Thanks in advance, Emad

pcarbo commented 4 years ago

@emadenany Please follow the instructions given at https://www.mathworks.com/support/compilers.

emadenany commented 4 years ago

@pcarbo Thank you very much. I have installed the MATLAB Support for MinGW-w64 C/C++ Compiler.

I couldn't find a FORTRAN compiler, could you help me find it?

When tried the command: mex -v -g -c -f mexopts_fortran.bat solver30.f I got: Error using mex C:\gpml-matlab-v4.2-2018-06-11\util\lbfgsb\mexopts_fortran.bat is not a valid XML file.

Could you help me on how to fix this issue?

Thank you,

pcarbo commented 4 years ago

Hi @emadenany, I'm sorry, I am not familiar with the Fortran compilers available on Windows; I work mainly in Linux and Mac environments.

emadenany commented 4 years ago

Hi @pcarbo thank you. Please, if I chose to install Linux, do I need to install Matlab on Linux too?

pcarbo commented 4 years ago

Yes, you would.

emadenany commented 4 years ago

Thank you very much.