|
From: Jason N. <ja...@ya...> - 2019-08-20 00:56:50
|
Dear Hannes, The simplest solution is for you to use Linux if you can. gfortran is natively supported by MATLAB on Linux. Kristján's method is correct for Windows. Using C to call into Fortran is your best option. On Windows, MinGW and MinGW-w64 versions of gfortran make the symbol names of functions lower case. MATLAB is looking for Uppercase symbols, and thus linking doesn't work (It has been several years since I have looked at this but I think what I said is correct). I was at the Mathworks Advisory Board meeting in June with the Mathworks developers in Boston. I told them about this issue on Windows and they said they would look into supporting gfortran on Windows. No promises though. They mentioned it was challenging. On Mon, Aug 19, 2019 at 8:35 AM Kristján Jónasson <jon...@hi...> wrote: > Dear Hannes, > > I believe gnumex is completely outdated by now. I have been using mex out > of the box with Matlab recently on my Mac with no problems, connecting with > C and then calling Fortran from C. I would use gfortran with the switch > -std=legacy. I would also use a C gateway function to connect between > Matlab and Fortran. I don’t know much about what would happen on a Windows > machine, but note that Matlab now claims to support > <https://www.mathworks.com/support/requirements/supported-compilers.html> MinGW > 6.3 C/C++. > > Depending on your C knowledge the effort could range from easy to > difficult. > > Here is a simple example: > > *#include** "mex.h"* > *// xy = prod_gw(x,y) calls prod.f do compute the scalar product dot(x,y)* > *// Returns silently with xy = 0 if not called with 2 arguments or if x > and y * > *// have different lengths. Other errors are not caught.* > > *void** prod_(**double** x[], **double** y[], **double** *xy, **int** > *n);* > > *void** mexFunction( **int** nlhs, mxArray *plhs[], **int** nrhs, const > mxArray *prhs[]) {* > *double** *xy, *x, *y;* > *int** n;* > * plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);* > * xy = mxGetPr(plhs[0]);* > * *xy = 0;* > *if** (nrhs != 2) **return**;* > * n = mxGetNumberOfElements(prhs[0]);* > *if** (n != mxGetNumberOfElements(prhs[0])) **return**;* > * x = mxGetPr(prhs[0]);* > * y = mxGetPr(prhs[1]);* > * *xy = 30;* > * prod_(x, y, xy, &n);* > *}* > > I could then have a compile-link script: > > *function** mexprod()* > *!/usr/local/bin/gfortran -c -std=legacy prod.f* > * mex **prod_gw.c* *prod.o* > *end* > > and compile and run with: > > * mexprod prod_gw([1 2], [3 4])* > *ans = * > * 11 * > > With the newest Matlab you could also use mxGetDoubles instead of mxGetPr > and mex with > > *mex -R2018a **prod_gw.c* *prod.o* > > (with no complex numbers you get the same results) > > Með kveðju/regards, Kristján > > Kristján Jónasson > prófessor > Námsbraut í tölvunarfræði / Department of Computer Science > Verkfræði- og náttúruvísindasvið / School of Engineering and > Natural Sciences > Háskóli Íslands / University of Iceland > Herb. 211, Tæknigarður, Dunhaga 5, Reykjavík > jon...@hi..., http://notendur.hi.is/jonasson > +354-5254735, +354-8228860 (mobile) > > > On 19 Aug 2019, at 14:07, Hannes Rox <han...@tu...> wrote: > > Dear Mr. Jonasson and Mr. Nicholson, > > First of all, I would like to thank you for providing gnumex for free > and with a very detailed documentation. Unfortunately, I still > have problems using it, so I would like to ask you if you can help me or > give me some advice. > > For my studies I have to use a code in Fortran 77 using the mex function > in Matlab. I have everything installed as described in the documentation. > I also tried it with the 32- and 64-bit version of MinGW. However, again > and again I get error/warning messages. > > > When running Gnumex.m, the warning comes after confirming "Make > options file": > > > Can not correct mex.pl - readme file in gnumex folder. > > I can't fix this, because this file doesn't exist on my PC (I can't find > a file named"mex.pl" anywhere). If I ignore the warning and create the > "options file" then comes following warning in the Command Window of Matlab: > > Warning: Could not copy the created mexopts.stp file to the directory: > C:\Program Files\MATLAB\R2018b\bin\win64\mexopts > This only means that commands such as mex.getCompilerConfigurations > will not work. It does not affect > the ability to compile mex or other files. To fix this problem you must > copy the contents of the file > C:\Users\hanne\AppData\Roaming\MathWorks\MATLAB\R2018b\mexopts.stp > to the file > C:\Program Files\MATLAB\R2018b\bin\win64\mexopts\GNUMEXOPTS.stp > The copyfile funtion reported the following error when it attempted this: > Zugriff verweigert > > I have fixed this as indicated. However, if I use now the mex function > in Matlab, this error message appears: > > Error using mex > No supported compiler was found. For options, visit > https://www.mathworks.com/support/compilers. > > So it doesn't work and since the Fortran code to be used is relatively > complex and long, it is unfortunately very time-consuming to transform the > code into Matlab. That's why it would help me a lot if I can do this with > Gnumex. If this is helpful for a possible fix, here are some facts about my > system: > > Matlab-Version: R2018b > Windows 10 (64 bit) > Intel Core i7-7500 > If you need further information or have any questions, I am glad to answer > them. > > Yours sincerely > Hannes Rox > > > |