Error with simple mex file
Show older comments
Hello,
I'm learning about mex files and trying to create a mex file that would double an input array from Fortran. I want the mex file to call the computational subroutine like in the matlab examples but I keep getting errors when the subroutine is compiled. The gateway is compiled just fine but the errors occur on the subroutine and I can't see why. Please see below errors:
>> mex doublevg.F doublevf.F
doublevf.F(3): error #5149: Illegal character in statement label field [s] subroutine doublev(y, x, m, n) -^ doublevf.F(3): error #5149: Illegal character in statement label field [u] subroutine doublev(y, x, m, n) --^ doublevf.F(3): error #5149: Illegal character in statement label field [b] subroutine doublev(y, x, m, n) ---^ doublevf.F(3): error #5149: Illegal character in statement label field [r] subroutine doublev(y, x, m, n) ----^ doublevf.F(3): error #5118: First statement in file must not be continued subroutine doublev(y, x, m, n) -----^ doublevf.F(3): error #5082: Syntax error, found END-OF-STATEMENT when expecting one of: ( % [ . = => subroutine doublev(y, x, m, n) -------------------------------^
doublevf.F(10): error #6353: A RETURN statement is invalid in the main program. return ------^
doublevf.F(7): error #6321: An unterminated block exists. do j=1,n
doublevf.F(6): error #6321: An unterminated block exists. do i=1,m
doublevf.F(4): error #6591: An automatic object is invalid in a main program. [Y] real*8 x(m,n), y(m,n)
doublevf.F(4): error #6591: An automatic object is invalid in a main program. [X] real*8 x(m,n), y(m,n)
doublevf.F(4): error #6219: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association [M] real*8 x(m,n), y(m,n)
doublevf.F(4): error #6219: A specification expression object must be a dummy argument, a COMMON block object, or an object accessible through host or use association [N] real*8 x(m,n), y(m,n)
compilation aborted for doublevf.F (code 1)
C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Compile of 'doublevf.F' failed.
Error using mex (line 206) Unable to complete successfully.
Here is the fortran subroutine. It's from the matsq.F example but just changed so the input array is doubled instead of squared.
!doublev computational routine
subroutine doublev(y, x, m, n)
real*8 :: x(m,n), y(m,n)
do i=1,m
do j=1,n
y(i,j)= x(i,j)*2
return
end
Any help would be appreciated.
Chris
Accepted Answer
More Answers (1)
hojjat
on 26 May 2013
0 votes
hello
this is error in building mex-file in my pc please help me!
mex -setup
Welcome to mex -setup. This utility will help you set up a default compiler. For a list of supported compilers, see http://www.mathworks.com/support/compilers/R2013a/win32.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler: [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2013a\sys\lcc [2] Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files\Microsoft Visual Studio 10.0 [3] Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0
[0] None
Compiler: 3
Please verify your choices:
Compiler: Microsoft Visual C++ 2010 Location: C:\Program Files\Microsoft Visual Studio 10.0
Are these correct [y]/n? y
************************************************************************* Warning: MEX-files generated using Microsoft Visual C++ 2010 require that Microsoft Visual Studio 2010 run-time libraries be available on the computer they are run on. If you plan to redistribute your MEX-files to other MATLAB users, be sure that they have the run-time libraries. *************************************************************************
Trying to update options file: C:\Users\eng\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2013a\bin\win32\mexopts\msvc100opts.bat
Done . . .
************************************************************************ Warning: The MATLAB C and Fortran API has changed to support MATLAB variables with more than 2^32-1 elements. In the near future you will be required to update your code to utilize the new API. You can find more information about this at: http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html Building with the -largeArrayDims option enables the new API. ************************************************************************
>>
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!