×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

help: Mex error

help: Mex error

help: Mex error

(OP)
Hi all,

I am new to Mex. I tried to compile a fortran code.

I use the following simple fortran code to test.
**********************************
    subroutine return_a(a)
    
    real, intent(out) :: a
    
    a=1

    end subroutine return_a
**********************************

the fortran compiler is Compaq Visual Fortran 6.6. Matlab is 7.2.0.232 (R2006)

In matlab command windows, I typed
mex -v return_a.f90

Then I got the following error message
 This is mex, Copyright 1984-2005 The MathWorks, Inc.
 
-> Default options filename found in C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2006a
----------------------------------------------------------------
->    Options file           = C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2006a\mexopts.bat
      MATLAB                 = C:\Program Files\MATLAB\R2006a
->    COMPILER               = df
->    Compiler flags:
         COMPFLAGS           = /fpp:"/m /SC:\Program Files\MATLAB\R2006a/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed
         OPTIMFLAGS          = /MD -Ox -DNDEBUG
         DEBUGFLAGS          = /MD -Zi
         arguments           =  
         Name switch         = /Fo
->    Pre-linking commands   =  
->    LINKER                 = link
->    Link directives:
         LINKFLAGS           = /DLL /EXPORT:_MEXFUNCTION@16 /MAP /LIBPATH:"C:\Program Files\MATLAB\R2006a\extern\lib\win32\microsoft" libmx.lib libmex.lib libmat.lib /implib:C:\DOCUME~1\Administrator\LOCALS~1\Temp_lib4621.lib /NOLOGO
     LINKDEBUGFLAGS      = /debug
         LINKFLAGSPOST       =  
         Name directive      = "/out:return_a.mexw32"
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @
->    Resource Compiler      = rc /fo "mexversion.res"
->    Resource Linker        =  
----------------------------------------------------------------
 
 
--> "df  /fpp:"/m /SC:\Program Files\MATLAB\R2006a/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed /FoC:\DOCUME~1\Administrator\LOCALS~1\Temp\return_a.obj /MD -Ox -DNDEBUG return_a.f90"
 
 
  C:\PROGRAM FILES\MATLAB\R2006A\BIN\MEX.PL: Error: Compile of 'return_a.f90' failed.
 
??? Error using ==> mex
Unable to complete successfully

What should I do to fix it?

Thanks?

RE: help: Mex error

I am guessing you did not put a wrapper around your core code and call the MATLAB API.  I have not done this for a while, but I think the examples show that you mex a wrapper that is the API supplied to you, and then you figure out how to send the API outputs to your core routine, and likewise your core routines output back to your wrappers API which goes back out to MATLAB.  I think the mex help explains it better.

RE: help: Mex error

(OP)
Thanks VisiGoth.

Actually I tried the examples that come with Matlab
in directory C:\Program Files\MATLAB\R2006a\extern\examples\mex\

I typed
mex -v yprime.f yprimefg.f
in matlab command windows, I got the same error message

-> Default options filename found in C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2006a
----------------------------------------------------------------
->    Options file           = C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2006a\mexopts.bat
      MATLAB                 = C:\Program Files\MATLAB\R2006a
->    COMPILER               = df
->    Compiler flags:
         COMPFLAGS           = /fpp:"/m /SC:\Program Files\MATLAB\R2006a/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed
         OPTIMFLAGS          = /MD -Ox -DNDEBUG
         DEBUGFLAGS          = /MD -Zi
         arguments           =  
         Name switch         = /Fo
->    Pre-linking commands   =  
->    LINKER                 = link
->    Link directives:
         LINKFLAGS           = /DLL /EXPORT:_MEXFUNCTION@16 /MAP /LIBPATH:"C:\Program Files\MATLAB\R2006a\extern\lib\win32\microsoft" libmx.lib libmex.lib libmat.lib /implib:C:\DOCUME~1\Administrator\LOCALS~1\Temp_lib6184.lib /NOLOGO
     LINKDEBUGFLAGS      = /debug
         LINKFLAGSPOST       =  
         Name directive      = "/out:yprime.mexw32"
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @
->    Resource Compiler      = rc /fo "mexversion.res"
->    Resource Linker        =  
----------------------------------------------------------------
 
 
--> "df  /fpp:"/m /SC:\Program Files\MATLAB\R2006a/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed /FoC:\DOCUME~1\Administrator\LOCALS~1\Temp\yprime.obj /MD -Ox -DNDEBUG yprime.f"
 
 
  C:\PROGRAM FILES\MATLAB\R2006A\BIN\MEX.PL: Error: Compile of 'yprime.f' failed.
 
??? Error using ==> mex
Unable to complete successfully

RE: help: Mex error

(OP)
Also tried this sample fortran code in the matlab help file. got the same error message.

C===========================================================
C     timestwo.f
C     Multiply the input argument by 2.
C
C     This is a MEX-file for MATLAB.
C     Copyright (c) 1984-2000 The MathWorks, Inc.
C     $Revision: 1.1.4.15 $
C===========================================================

C     Computational subroutine
      subroutine timestwo(y, x)
      real*8 x, y

      y = 2.0 * x
      return
      end


C     The gateway routine
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)

      integer mxGetM, mxGetN, mxGetPr
      integer mxIsNumeric, mxCreateDoubleMatrix
      integer plhs(*), prhs(*)
      integer x_pr, y_pr
      integer nlhs, nrhs
      integer m, n, size
      real*8 x, y

C     Check for proper number of arguments.
      if(nrhs .ne. 1) then
         call mexErrMsgTxt('One input required.')
      elseif(nlhs .ne. 1) then
         call mexErrMsgTxt('One output required.')
      endif

C     Get the size of the input array.
      m = mxGetM(prhs(1))
      n = mxGetN(prhs(1))
      size = m*n

C     Check to ensure the input is a number.
      if(mxIsNumeric(prhs(1)) .eq. 0) then
         call mexErrMsgTxt('Input must be a number.')
      endif

C     Create matrix for the return argument.
      plhs(1) = mxCreateDoubleMatrix(m, n, 0)
      x_pr = mxGetPr(prhs(1))
      y_pr = mxGetPr(plhs(1))
      call mxCopyPtrToReal8(x_pr, x, size)

C     Call the computational subroutine.
      call timestwo(y, x)

C  Load the data into y_pr, which is the output to MATLAB.
      call mxCopyReal8ToPtr(y, y_pr, size)     

      return
      end

RE: help: Mex error

I attempted to compile with FORTRAN.  I had the same Copaq version 6.6.  I had an old Digital Equp. v6.0, so some of my link libraries might be old.  But I think you might have a problem making the .obj.

For some reason my comlpiler is called fl32 and your is df.  I used the mex -setup to do the work.

I had a problem linking.  The linker could not find my Microsoft supplied "mspdb71.dll".  I found it and copied it to my working directory (a hack).

I could not find anything different with your setup.  I am supplying my -v output in case you can see someting.  I think the two different call names to the comppiler do not matter.  I have an older MATLAB version, so maybe mine is behind the times.

You have an odd name for the directory to send the .obj.  Maybe this old tool has aproblem with that.  You could change our mexopts.bat and execute it.  Or maybe just try to move to a directory at a root or at least without spaces in the name.  Just to see if this is where the problem is.  It seems you are not getting an indication of what the problem is.  The .pl is just giving you a fail notice.


>> mex -v yprimef.f yprimefg.f
 This is mex, Copyright 1984-2003 The MathWorks, Inc.
 
-> Default options filename found in C:\Documents and Settings\solarjo2\Application Data\MathWorks\MATLAB\R14
----------------------------------------------------------------
->    Options file           = C:\Documents and Settings\solarjo2\Application Data\MathWorks\MATLAB\R14\mexopts.bat
      MATLAB                 = E:\MATLAB
->    COMPILER               = fl32
->    Compiler flags:
         COMPFLAGS           = /fpp:"/m /SE:\MATLAB/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed
         OPTIMFLAGS          = /MD -Ox -DNDEBUG
         DEBUGFLAGS          = /MDd -Zi
         arguments           =  
         Name switch         = /Fo
->    Pre-linking commands   =  
->    LINKER                 = link
->    Link directives:
         LINKFLAGS           = /DLL /EXPORT:_MEXFUNCTION@16 /LIBPATH:"E:\MATLAB\extern\lib\win32\digital\df60" libmx.lib libmex.lib libmat.lib /implib:_lib8531.lib /NOLOGO
         LINKFLAGSPOST       =  
         Name directive      = "/out:yprimef.dll"
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @
->    Resource Compiler      = rc /fo "mexversion.res"
->    Resource Linker        =  
----------------------------------------------------------------
 
 
--> "fl32  /fpp:"/m /SE:\MATLAB/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed /Foyprimef.obj /MD -Ox -DNDEBUG yprimef.f"
 
yprimef.i
 
--> "fl32  /fpp:"/m /SE:\MATLAB/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed /Foyprimefg.obj /MD -Ox -DNDEBUG yprimefg.f"
 
yprimefg.i
    Contents of 8531_tmp.rsp:
  yprimef.obj  yprimefg.obj
 
 
--> "link "/out:yprimef.dll" /DLL /EXPORT:_MEXFUNCTION@16 /LIBPATH:"E:\MATLAB\extern\lib\win32\digital\df60" libmx.lib libmex.lib libmat.lib /implib:_lib8531.lib /NOLOGO  @8531_tmp.rsp "
 
   Creating library _lib8531.lib and object _lib8531.exp
>>

jsolar

RE: help: Mex error

(OP)
Thank you, VisiGoth.

Could you tell me how to change the directory that .obj is sent to?

RE: help: Mex error

It is done by the line in your mexopts.batr file
set NAME_OBJECT=/Fo
But I see that your line matches mine, so that must not be the problem.

I noticed that your output showed a strange path name for setting LINKFLAGS.
/implib:C:\DOCUME~1\Administrator\LOCALS~1\Temp_lib6184.lib

In mine it is
set LINKFLAGS=/DLL /EXPORT:_MEXFUNCTION@16 /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:%LIB_NAME%.lib /NOLOGO

Notice the simpler /implib path.

You might try finding the mexopts.bat that was generated when you did the mex -setup.    Then edit it to either remove the path name you have with the ~ in them, or hardcode the full path name.  Double quotes might work to protect the spaces, but if not try the single quote.

Then run the .bat file.  Either in your MATLAB environment using the bang oeprator ! or from windows start run.  You will need the full path name I think.

Then after the .bat file executes, try compiling and see if the error message changes.

jsolar

RE: help: Mex error

(OP)
The following is the mexopts.bat. I did not find any place to change /implib:C:\DOCUME~1\Administrator\LOCALS~1\Temp_lib6184.lib.

@echo off
rem CVF66OPTS.BAT
rem
rem    Compile and link options used for building MEX-files
rem    using the Compaq Visual Fortran compiler version 6.6
rem
rem    $Revision $  $Date: 2006/01/13 20:56:13 $
rem
rem *******************************************************
rem General parameters
rem *******************************************************
set MATLAB=%MATLAB%
set DF_ROOT=C:\Program Files\Microsoft Visual Studio
set VCDir=%DF_ROOT%\VC98
set MSDevDir=%DF_ROOT%\Common\msdev98
set DFDir=%DF_ROOT%\DF98
set PATH=%MSDevDir%\bin;%DFDir%\BIN;%VCDir%\BIN;%PATH%
set INCLUDE=%DFDir%\INCLUDE;%INCLUDE%
set LIB=%DFDir%\LIB;%VCDir%\LIB;%LIB%

rem *****************************************************
rem Compiler parameters
rem *******************************************************
set COMPILER=df
set COMPFLAGS=/fpp:"/m /S%MATLAB%/extern/include" -c -nokeep -G5 -nologo -DMATLAB_MEX_FILE /fixed
set OPTIMFLAGS=/MD -Ox -DNDEBUG
set DEBUGFLAGS=/MD -Zi
set NAME_OBJECT=/Fo

rem ******************************************************
rem Linker parameters
rem ******************************************************
set LIBLOC=%MATLAB%\extern\lib\win32\microsoft
set LINKER=link
set LINKFLAGS=/DLL /EXPORT:_MEXFUNCTION@16 /MAP /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:%LIB_NAME%.lib /NOLOGO
set LINKOPTIMFLAGS=
set LINKDEBUGFLAGS=/debug
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT="/out:%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=@

rem *******************************************************
rem Resource compiler parameters
rem *******************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=

set POSTLINK_CMDS=del "%OUTDIR%%MEX_NAME%.map"

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources