Problem sloved. It seems that Matlab R2014a does not allow to compile Fortran and C in a single MEX call. I believe that it allowed to link the files automatically.
I had to compile the Fortran code to .o objects and link them to the .c files manually.
I managed to compile the Fortran part by splitting into 2 MEX calls:
mex Lbfgsb.3.0/lbfgsb.f Lbfgsb.3.0/linpack.f Lbfgsb.3.0/timer.f -lm -lmwblas CFLAGS="\$CFLAGS -O3"FC="gfortran"
mex -v lbfgsb_wrapper.c -largeArrayDims -UDEBUG ;
The Fortran part is fine, but not the C compilation. I get the following error message:
Error using mex
/tmp/mex_29407351995475_5199/lbfgsb_wrapper.o: In function `mexFunction':
lbfgsb_wrapper.c:(.text+0x738): undefined reference to `setulb_'
collect2: error: ld returned 1 exit status
I have tried to play with the -DNOUNDERSCORE -UUPPERCASE_FORTRAN flags but none of them seem to help.
How can I fix this issue?
Thank you very much
I have tried to compile it under Linux Mint 17, with Matlab 2014a. I got the following error message:
Error using mex
Cannot compile both C and FORTRAN source files in a single call to MEX.
Error in compile_mex (line 61)
mex -v lbfgsb_wrapper.c -largeArrayDims -UDEBUG ...
I've tried to find out about this error but it is nowhere to be found, as if it is an issue related to Matlab 2014 only.
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.