Create Mex files for Matlab, from .FOR files of Fortran

5 views (last 30 days)
Hello. there are files with the .FOR extension, in which the subroutine codes are written in the Fortran language. I want to create Mex files from these files, which can be run in matlab. how to do it?

Answers (4)

dpb
dpb on 12 Aug 2023
Edited: dpb on 13 Aug 2023
Which OS? For Linux, the GNU Fortran compiler is supported, for Windows and Mac only a recent version of the Intel compiler is supported.
It's unconscionable that TMW supports GNU for Linux but not for Windows and Mac; I, at least, have had no success in figuring out how to link although since it supports the GNU C compiler that the Fortran compiler is built on, it surely should be possible -- excepting for the name-mangling issues.
And, TMW has essentially quit supporting Fortran at all; the example files are still horribly outdated F77-style fixed-format with archaic at best non-standard syntax and other style problems.
You probably have a real challenge on your hands; the alternative may be to write interface routines in C and then have those call the Fortran code instead of trying to build direct Fortran mex interfaces.
@James Tursa is the real guru; hopefully he'll see and comment and have better pointers; my patience was exhausted some years ago and, fortunately, the need for additional support for the application I supported for a client while still consulting has, apparently, either gone away or they've found an alternate way so I've just given up.

James Tursa
James Tursa on 12 Aug 2023
Edited: James Tursa on 12 Aug 2023
So, I haven't had access to a Fortran compiler in over 10 years. And as a result I haven't been maintaining any of my Fortran FEX submissions. Kinda sad that this very fast matrix/array based language with the same memory-element order as MATLAB does not have free solutions for connecting with MATLAB, at least not for Windows, but that's the way it is. And @dpb, the Fortran examples supplied by TMW still have the same bugs in them, and the compile files probably still have the stupid /fixed option (forces free form source code to be compiled as fixed form source code ... generating lots of faux errors), that I pointed out over 10 years ago. I just submitted another request that they change this. Sigh ...
My suggestion depends on what your Fortran code does, and whether it has user I/O. If it is just number crunching, I would probably use whatever Fortran compiler you have to create .obj files. Then write a simple wrapper mex file in C that acts as a conduit for the input & output variables. Then just mex the wrapper C file and Fortran .obj files together.
If your code has user I/O, that is a whole different ball game ...
So, what does your Fortran code do? What are the inputs and outputs? Can you post the interface function signatures for us? Maybe we can quickly write the wrapper code for you.
  13 Comments
dpb
dpb on 16 Aug 2023
Edited: dpb on 16 Aug 2023
@James Tursa, "and fixed format had to use .f instead of .for, but it works!"
The above seems peculiar, <the Intel doc> still says that .f and .for are both assumed by the compiler to be fixed format source form (as well as .ftn and .i).
While the /fixed switch is there in the shipped .xml files, if you've removed it, then I wonder where TMW has managed to override that behavior in the mex configuration scripts -- stuff like that that is so obfuscated is what finally drove me nuts and to just give up when couldn't still use the old CVF compiler which wouldn't run on the 64-bit OS since no longer had a paying client to foot the bills and make the effort worthwhile other than just having the facility when wanted it.
Hmmmm....does it somehow have something to do with the preprocessor, maybe? I never got into the habit of preprocessing Fortran files but mex does it automagically because the include files have lot of #defines in them for type definitions, etc., ... I hate their style, but it is what it is.
dpb
dpb on 17 Aug 2023
Edited: dpb on 4 Oct 2023
Well, I download/installed, too, and mex -setup fails to find the Intel 2023 compiler...it's installed and works as
C:\Users\owner>ifx hello.f90
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2023.2.0 Build 20230627
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.
Microsoft (R) Incremental Linker Version 14.29.30151.0
Copyright (C) Microsoft Corporation. All rights reserved.
-out:hello.exe
-subsystem:console
hello.obj
C:\Users\owner>hello
Hello, world!
C:\Users\owner>
illustrates, but
>> strvcat(supported.MexOpt)
ans =
10×58 char array
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_18_vs2015.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_18_vs2017.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_18_vs2019.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_19_vs2015.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_19_vs2017.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_19_vs2019.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_20_vs2017.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_20_vs2019.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_21_vs2017.xml'
'C:\ML_R2021b\bin\win64\mexopts\intel_fortran_21_vs2019.xml'
>> mex -setup FORTRAN
Error using mex
Supported compiler not detected. For options, visit https://www.mathworks.com/support/compilers.
>>
I've no klew at this point yet as to how to make it find it...I'm pretty sure it must have to do with where/how mex searches, but they give no hints as to how that does/does not work in order to be able to prod it in the right direction.
I let the install use the default location...
I dunno, did you use VS and build inside it instead, maybe? I've never tried that; always just wrote code with my preferred toolset and then compiled/linked. W/ CVF in the olden days I could do all that inside the Brief editor but it also won't run on these systems any more, sadly.

Sign in to comment.


roborrr
roborrr on 16 Aug 2023
Edited: roborrr on 16 Aug 2023
Dear James Tursa. I installed "Intel Fortran Compiler Classic and Intel Fortran Compiler for Windows*" as you suggested. What command to give to matlab so that from the Fortran file "example. For" created the mex file?
Я даю команду 'mex -v -fortran example.f -output example_mex' и получаю сообщение об ошибке : "Did not find installed compiler 'Intel Parallel Studio XE 2018 for Fortran with Microsoft Visual Studio 2017'."
  6 Comments
dpb
dpb on 16 Aug 2023
Actually one can see the switches used for gfortran on the unix platform using the above; but I couldn't figure out a way to get a copy of the saved struct variable to a local file from the remote platform to be able to poke at it in a more leisurely fashion. At some point, might retry that exercise again with that guiding light...
dpb
dpb on 17 Aug 2023
@dpb wrote earlier "There's a define in the .xml file for the compiler location $FORTRANROOT where it expects the installation to be; I'm not positive who is responsible for defining that variable;"
Aha! I just found it; I had quite scrolling in the .xml files after the compiler/linker definitions; there's a very convoluted search logic written in xml as
<locationFinder>
<FORTRANROOT>
<or>
<and>
<or>
<envVarExists name="IFORT_COMPILER22" />
</or>
<fileExists name="$$/Bin/intel64/ifort.exe" />
<dirExists name="$$/../.." />
</and>
<and>
<or>
<envVarExists name="ONEAPI_ROOT" />
</or>
<fileExists name="$$/compiler/latest/windows/Bin/intel64/ifort.exe" />
<dirExists name="$$/../.." />
</and>
<and>
<or>
<envVarExists name="ONEAPI_ROOT" />
</or>
<fileExists name="$$/compiler/2021.1.1/windows/Bin/intel64/ifort.exe" />
<dirExists name="$$/../.." />
</and>
</or>
</FORTRANROOT>
<VCROOT>
<or>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%" />
</and>
</or>
</VCROOT>
<SDKROOT>
<or>
<hklmExists path="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" />
<hkcuExists path="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" />
<hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" />
<hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0" name="InstallationFolder" />
</or>
</SDKROOT>
<VSINSTALLDIR>
<or>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" />
</and>
</or>
</VSINSTALLDIR>
<VCINSTALLDIR>
<or>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" />
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" />
<cmdReturns name="set &quot;vcroot=$$&quot;&amp;for /f &quot;delims= &quot; %a in ('type &quot;$$\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt&quot;') do @if exist &quot;$$\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe&quot; call echo %vcroot%\VC\Tools\MSVC\%a" />
</and>
</or>
</VCINSTALLDIR>
<VCVARSALLDIR>
<or>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Enterprise -property installationPath -format value" />
<fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" />
<dirExists name="$$"/>
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Professional -property installationPath -format value" />
<fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" />
<dirExists name="$$"/>
</and>
<and>
<envVarExists name="ProgramFiles(x86)" />
<fileExists name="$$\Microsoft Visual Studio\Installer\vswhere.exe" />
<cmdReturns name="&quot;$$\\vswhere.exe&quot; -version &quot;[16.0,18.0)&quot; -products Microsoft.VisualStudio.Product.Community -property installationPath -format value" />
<fileExists name="$$\VC\Auxiliary\Build\vcvarsall.bat" />
<dirExists name="$$"/>
</and>
</or>
</VCVARSALLDIR>
<KITSROOT>
<or>
<hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hklmExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hkcuExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
</or>
</KITSROOT>
<SDKVERSION>
<and>
<or>
<hklmExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hkcuExists path="SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hklmExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
<hkcuExists path="SOFTWARE\Microsoft\Windows Kits\Installed Roots" name="KitsRoot10" />
</or>
<!-- For each folder inside '<KITSROOT>\include' check for 'ucrt' and if exists return that folder name -->
<cmdReturns name="echo off&amp;set &quot;sdkversion=&quot;&amp;(for /f %a IN ('dir &quot;$$\include\&quot; /b /ad-h /on') do ( @if exist &quot;$$\include\%a\ucrt\&quot; set &quot;sdkversion=%a&quot; ))&amp;call echo %sdkversion%" />
</and>
</SDKVERSION>
</locationFinder>
The above has buried in it expected install paths and version numbers; I've yet to dive totally into the constants here but looks like one copy of the ifort.exe compiler on the installed path should match this expected one; the ONEAPI_ROOT environment variable is set. The version returned is
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\intel64>ifort
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000
which returns 2021.10 as a version whereas the xml file just says "21.0". I'm not sure if that's an/the issue or not or whether the fact it installed in a folder ..\2023.2.1 instead of ..\2021.1.1 that's buried in the script. Although superfiically it looks like it should have matched the earlier <or> under "../latest/windows/Bin/intel64/" because there's a copy of ifort.exe there, too.
Why they have to make this so complicated...and give no diagnostics nor ways to fix if something does go wrong....

Sign in to comment.


roborrr
roborrr on 19 Aug 2023
I installed the following programs: Matlab R2018b, Intel Parallel Studio XE 2018 for Fortran, Microsoft Visual Studio 2017. There is a TRUSS.f file that contains the following Fortran code (for example):
SUBROUTINE TRUSS
IMPLICIT REAL*8(A-H,O-Z)
COMMON /DIM/ N1,N2,N3,N4,N5,N6,N7,N8,N9,N10,N11,N12,N13,N14,N15
COMMON /SOL/ NUMNP,NEQ,NWK,NWM,NWC,NUMEST,MIDEST,MAXEST,NSTE,MA
COMMON /EL/ IND,ICOUNT,NPAR(20),NUMEG,NEGL,NEGNL,IMASS,IDAMP,ISTAT
1 ,NDOF,KLIN,IEIG,IMASSN,IDAMPN
COMMON /VAR/ NG,KPRI,MODEX,KSTEP,ITE,ITEMAX,IREF,IEQREF,INOCMD
COMMON A(30000)
EQUIVALENCE (NPAR(2),NUME),(NPAR(16),NUMMAT),(NPAR(17),NCON)
N101=1
N102=N101 + NUMMAT
N103=N102 + NUMMAT
N104=N103 + NUMMAT
N105=N104 + NUMMAT
N106=N105 + 6*NUME
N107=N106 + 6*NUME
N108=N107 + NUME
N109=N108 + NUME
N110=N109 + NUME
NLAST=N110 + NCON*NUMMAT - 1
IF (NLAST.LE.NUMEST) GO TO 100
WRITE (6,2000) NLAST
STOP
100 MIDEST=NLAST
IF (IND.GT.3) GO TO 110
M2=N2
M3=N3
M4=N4
M5=N5
GO TO 120
110 M2=N2
M3=N7
M4=N8
M5=N3
IF (ICOUNT.LT.3) GO TO 120
M2=N6
M5=N5
120 CALL RUSS(A(N1),A(M2),A(M3),A(M4),A(M5),A(N101),A(N102),A(N103),
1 A(N104),A(N105),A(N106),A(N107),A(N108),A(N109),
2 A(N110),NCON,NDOF)
RETURN
2000 FORMAT (///40H *** ERROR NUMEST MUST BE INCREASED TO , I6)
END
Then I give the command:
mex -v -largeArrayDims -fortran TRUSS.f -output truss_mex
and get in response:
Verbose mode is on.
... Looking for compiler 'Intel Parallel Studio XE 2018 for Fortran with Microsoft Visual Studio 2017' ...
... Looking for environment variable 'IFORT_COMPILER18' ...Yes ('C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows\').
... Looking for file 'C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows\Bin\intel64\ifort.exe' ...Yes.
... Looking for folder 'C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Executing command 'set "vcroot=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"&for /f "delims= " %a in ('type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"') do @if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe" call echo %vcroot%' ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Executing command 'set "vcroot=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional"&for /f "delims= " %a in ('type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"') do @if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\%a\bin\HostX64\x64\cl.exe" call echo %vcroot%\VC\Tools\MSVC\%a' ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428').
... Looking for registry setting 'HKLM\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKCU\SOFTWARE\Microsoft\VisualStudio\SxS\VS7' 15.0 ...No.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\SxS\VS7' 15.0 ...Yes ('C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\').
... Looking for file 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat' ...Yes.
... Looking for folder 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build' ...Yes.
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Looking for registry setting 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows Kits\Installed Roots' KitsRoot10 ...Yes ('C:\Program Files (x86)\Windows Kits\10\').
... Executing command 'echo off&set "sdkversion="&(for /f %a IN ('dir "C:\Program Files (x86)\Windows Kits\10\include\" /b /ad-h /on') do ( @if exist "C:\Program Files (x86)\Windows Kits\10\include\%a\ucrt\" set "sdkversion=%a" ))&call echo %sdkversion%' ...Yes ('10.0.17134.0').
Found installed compiler 'Intel Parallel Studio XE 2018 for Fortran with Microsoft Visual Studio 2017'.
Set PATH = C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows\bin\intel64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\bin\HostX64\x64\;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\vcpackages;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\Tools;C:\Program Files (x86)\Windows Kits\10\\Bin\10.0.17134.0\x64;C:\Program Files (x86)\Windows Kits\10\\Bin\10.0.17134.0\x86;C:\Program Files (x86)\Windows Kits\10\\Bin\x64;C:\Program Files (x86)\Windows Kits\10\\Bin\x86;;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows\mpi\intel64\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\mpirt;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\ia32_win\compiler;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\emu;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\intel64\libfabric\bin\;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\intel64\libfabric\bin\utils;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\intel64\bin;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\ia32;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\intel64;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Program Files\MATLAB\MATLAB Runtime\v95\runtime\win64;C:\Program Files\dotnet\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\MATLAB\R2018b\runtime\win64;C:\Program Files\MATLAB\R2018b\bin;C:\Users\PC\AppData\Local\Microsoft\WindowsApps;C:\Users\PC\AppData\Local\Microsoft\WindowsApps;
Set INCLUDE = C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\include;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\winrt;C:\Program Files\MATLAB\R2018b\extern\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\include;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.17134.0\winrt;C:\Program Files\MATLAB\R2018b\extern\include;
Set LIB = C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows/compiler/lib/intel64_win;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\\Lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.17134.0\um\x64;C:\Program Files\MATLAB\R2018b\lib\win64;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows/compiler/lib/intel64_win;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\lib\x64;C:\Program Files (x86)\Windows Kits\10\\Lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.17134.0\um\x64;C:\Program Files\MATLAB\R2018b\lib\win64;
Set LIBPATH = C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows/compiler/lib/intel64_win;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\lib\x64;C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows/compiler/lib/intel64_win;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\lib\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428\atlmfc\lib\x64;
Options file details
-------------------------------------------------------------------
Compiler location: C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows
Options file: C:\Users\PC\AppData\Roaming\MathWorks\MATLAB\R2018b\mex_FORTRAN_win64.xml
CMDLINE200 : link /nologo /manifest /INCREMENTAL:NO /DLL /EXPORT:MEXFUNCTION /EXPORT:MEXFILEREQUIREDAPIVERSION C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj /LIBPATH:"C:\Program Files\MATLAB\R2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64
CMDLINE250 : mt -outputresource:C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64;2 -manifest "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64.manifest"
CMDLINE300 : del "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.exp" "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.lib" "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64.manifest" "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.ilk"
COMPILER : ifort
COMPFLAGS : /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64
COMPDEFINES : /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE
MATLABMEX : /DMATLAB_MEX_FILE
OPTIMFLAGS : /O2 /DNDEBUG
INCLUDE : -I"C:\Program Files\MATLAB\R2018b\extern\include"
DEBUGFLAGS : /Z7
LINKER : link
LINKFLAGS : /nologo /manifest /INCREMENTAL:NO
LINKTYPE : /DLL
LINKEXPORT : /EXPORT:MEXFUNCTION
LINKEXPORTVER : /EXPORT:MEXFUNCTION /EXPORT:MEXFILEREQUIREDAPIVERSION
LINKLIBS : /LIBPATH:"C:\Program Files\MATLAB\R2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
LINKDEBUGFLAGS : /debug /PDB:"C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64.pdb"
LINKOPTIMFLAGS :
OBJEXT : .obj
LDEXT : .mexw64
SETENV : set COMPILER=ifort
set COMPFLAGS=/c /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64 /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE
set OPTIMFLAGS=/O2 /DNDEBUG
set DEBUGFLAGS=/Z7
set LINKER=link
set LINKFLAGS= /nologo /manifest /INCREMENTAL:NO /export:%ENTRYPOINT% /DLL /LIBPATH:"C:\Program Files\MATLAB\R2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /EXPORT:MEXFUNCTION
set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%.mexw64.pdb"
set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
FORTRANROOT : C:\Program Files (x86)\IntelSWTools\compilers_and_libraries_2018.3.210\windows
VCROOT : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional
SDKROOT : C:\Program Files (x86)\Windows Kits\10\
VSINSTALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
VCINSTALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.14.26428
VCVARSALLDIR : C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build
KITSROOT : C:\Program Files (x86)\Windows Kits\10\
SDKVERSION : 10.0.17134.0
MATLABROOT : C:\Program Files\MATLAB\R2018b
ARCH : win64
SRC : "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\TRUSS.f";"C:\Program Files\MATLAB\R2018b\extern\version\fortran_mexapi_version.F"
OBJ : C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj;C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj
OBJS : C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj
SRCROOT : C:\Users\PC\Dropbox\fortran_to_matlab\FOR\TRUSS
DEF : C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\truss_mex.def
EXP : "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.exp"
LIB : "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.lib"
EXE : C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64
ILK : "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.ilk"
MANIFEST : "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64.manifest"
TEMPNAME : C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex
EXEDIR : C:\Users\PC\Dropbox\fortran_to_matlab\FOR\
EXENAME : truss_mex
OPTIM : /O2 /DNDEBUG
LINKOPTIM :
CMDLINE100_0 : ifort /c /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64 /O2 /DNDEBUG "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\TRUSS.f" /FoC:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj
CMDLINE100_1 : ifort /c /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64 /O2 /DNDEBUG "C:\Program Files\MATLAB\R2018b\extern\version\fortran_mexapi_version.F" /FoC:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj
-------------------------------------------------------------------
Building with 'Intel Parallel Studio XE 2018 for Fortran with Microsoft Visual Studio 2017'.
ifort /c /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64 /O2 /DNDEBUG "C:\Users\PC\Dropbox\fortran_to_matlab\FOR\TRUSS.f" /FoC:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj
ifort /c /nologo /fpp /Qprec /fixed /MD /fp:source /assume:bscc -I"C:\Program Files\MATLAB\R2018b\extern\include" /DMX_COMPAT_64 /DMATLAB_DEFAULT_RELEASE=R2017b /DUSE_MEX_CMD /DMATLAB_MEX_FILE /integer-size:64 /O2 /DNDEBUG "C:\Program Files\MATLAB\R2018b\extern\version\fortran_mexapi_version.F" /FoC:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj
link /nologo /manifest /INCREMENTAL:NO /DLL /EXPORT:MEXFUNCTION /EXPORT:MEXFILEREQUIREDAPIVERSION C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\TRUSS.obj C:\Users\PC\AppData\Local\Temp\mex_257310570028391_11568\fortran_mexapi_version.obj /LIBPATH:"C:\Program Files\MATLAB\R2018b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.mexw64
The file 'truss_mex.mexw64' is created, but matlab gives the following error message:
LINK : error LNK2001: �������������������������� �������������� ������������ "MEXFUNCTION"
C:\Users\PC\Dropbox\fortran_to_matlab\FOR\truss_mex.lib : fatal error LNK1120: ��������������������������
�������������� ������������������: 1
Then I give the command 'mex -setup Fortran' and get in response:
MEX configured to use 'Intel Parallel Studio XE 2018 for Fortran with Microsoft Visual Studio 2017' for FORTRAN language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. You will be required
to update your code to utilize the new API.
You can find more information about this at:
https://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
What commands and in what place should I give so that my data is updated properly and no errors appear.
  7 Comments
Walter Roberson
Walter Roberson on 20 Aug 2023
The document I was looking for said that size could differ for blank common but that the types needed to be the same for all versions; for named common it said the size and types had to be identical.
dpb
dpb on 20 Aug 2023
Edited: dpb on 20 Aug 2023
The restriction that named common blocks be the same size is so. Names can change positionally and type punning by EQUIVALENCE.
I'd guess it's pretty unlikely those are used in OP's code, but it's always possible and the safest (and simplest to try to mex this) route is to simply duplicate COMMON as is...the listing doesn't show an INCLUDE statement to bring in the COMMON; that could be original source doesn't use it or the posted came from listing that doesn't reflect preprocessing.
NOT using INCLUDE but having duplicate code in multiple program units is one of the most common ways to mess up and unintentionally change variables via common; a change in the block definition has to be faithfully duplicated everywhere in that case; it's all too easy to miss one or make a typo when are many to do.
A code I supported for years I've referred to often in the past deliberately uses the type punning in its database to, in various program units or for various purposes, refer to same memory locations as REAL or INTEGER variable types; I'd've never designed it that way, but the original authors did and it works very well; is just difficult to grasp initially. It, however, also uses C helper routines that move those data bytes by straight bit copying via memmove() when storing. Anyways, gotten way off track for OP's issues...

Sign in to comment.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!