Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple compilation procedure with MATLAB R2014a #2

Closed
nolyn opened this issue Jul 18, 2014 · 10 comments
Closed

Simple compilation procedure with MATLAB R2014a #2

nolyn opened this issue Jul 18, 2014 · 10 comments

Comments

@nolyn
Copy link

nolyn commented Jul 18, 2014

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
Copy link
Owner

pcarbo commented Jul 22, 2014

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

@pcarbo pcarbo closed this as completed Jul 23, 2014
@chandreshiit
Copy link

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
Copy link
Owner

pcarbo commented Mar 16, 2016

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

@emadenany
Copy link

emadenany commented Jul 11, 2020

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
Copy link
Owner

pcarbo commented Jul 13, 2020

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

@emadenany
Copy link

@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
Copy link
Owner

pcarbo commented Jul 14, 2020

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
Copy link

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

@pcarbo
Copy link
Owner

pcarbo commented Jul 14, 2020

Yes, you would.

@emadenany
Copy link

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants