f



matlab mex file (fortran)

I want to create the mex file from external fortran file (file.for).
I use compaq visual fortran 6.6a and matlab v13. Pleas help me. I
have still the same problem.
------------------------------------------------------
>> mex -setup
Please choose your compiler for building external interface (MEX)
files:
 
Would you like mex to locate installed compilers [y]/n? y
 
Select a compiler:
[1] Compaq Visual Fortran version 6.6 in C:\Program Files\Microsoft
Visual Studio
[2] Lcc C version 2.4 in C:\MATLAB6P5\sys\lcc
[3] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft
Visual Studio
 
[0] None
 
Compiler: 1
 
Please verify your choices:
 
Compiler: Compaq Visual Fortran 6.6
Location: C:\Program Files\Microsoft Visual Studio
 
Are these correct?([y]/n): y
 
The default options file:
"C:\Documents and Settings\Administrator\Application
Data\MathWorks\MATLAB\R13\mexopts.bat"
is being updated from C:\MATLAB6P5\BIN\WIN32\mexopts\df66opts.bat...
 
>> mex cel.f
   Creating library _lib4119.lib and object _lib4119.exp
_lib4119.exp : error LNK2001: unresolved external symbol
_MEXFUNCTION@16
cel.dll : fatal error LNK1120: 1 unresolved externals
 
  C:\MATLAB6P5\BIN\WIN32\MEX.PL: Error: Link of 'cel.dll' failed.
 
??? Error using ==> mex
Unable to complete successfully
------------------------------------------------------
thx
0
markuj (10)
8/26/2005 5:06:29 PM
comp.soft-sys.matlab 211266 articles. 24 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
707 Views

Similar Articles

[PageSpeed] 0

It looks like your compiler is now setup right. Could you post your
fortran code? It should follow this basic format.

      Subroutine mexFunction(nlhs, plhs, nrhs, prhs)

      integer nlhs, nrhs
      integer plhs(*), prhs(*)
C Body
      return
      end

Also, when I first installed my 7.0.4 version, I installed it to a
custom location whose path had spaces in it. This ended up causing
errors when trying to run mex. I don't remember exactly what they
were but you may want to check that too. I fixed it by editing the
mexopts.bat file, reinstalling to the default location would have
worked too. You may want to check out that mexopts.bat file anyway
to make sure the various parameters look correct.

regards
mark

marcin kujawa wrote:
>
>
> I want to create the mex file from external fortran file
> (file.for).
> I use compaq visual fortran 6.6a and matlab v13. Pleas help me. I
> have still the same problem.
> ------------------------------------------------------
>>> mex -setup
> Please choose your compiler for building external interface (MEX)
> files:
>
> Would you like mex to locate installed compilers [y]/n? y
>
> Select a compiler:
> [1] Compaq Visual Fortran version 6.6 in C:\Program Files\Microsoft
> Visual Studio
> [2] Lcc C version 2.4 in C:\MATLAB6P5\sys\lcc
> [3] Microsoft Visual C/C++ version 6.0 in C:\Program
> Files\Microsoft
> Visual Studio
>
> [0] None
>
> Compiler: 1
>
> Please verify your choices:
>
> Compiler: Compaq Visual Fortran 6.6
> Location: C:\Program Files\Microsoft Visual Studio
>
> Are these correct?([y]/n): y
>
> The default options file:
> "C:\Documents and Settings\Administrator\Application
> Data\MathWorks\MATLAB\R13\mexopts.bat"
> is being updated from
> C:\MATLAB6P5\BIN\WIN32\mexopts\df66opts.bat...
>
>>> mex cel.f
> Creating library _lib4119.lib and object _lib4119.exp
> _lib4119.exp : error LNK2001: unresolved external symbol
> _MEXFUNCTION@16
> cel.dll : fatal error LNK1120: 1 unresolved externals
>
> C:\MATLAB6P5\BIN\WIN32\MEX.PL: Error: Link of 'cel.dll' failed.
>
> ??? Error using ==> mex
> Unable to complete successfully
> ------------------------------------------------------
> thx
0
8/26/2005 10:10:45 PM
This is my mexopts.bat file. Is it correct?
I send you my hypothetical fortran code too.
-----------------------------------------------------------
@echo off
rem DF66OPTS.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: 1.1 $ $Date: 2002/06/03 12:17: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=fl32
set COMPFLAGS=/fpp:"/m /S%MATLAB%/extern/include" -c -nokeep -G5
-nologo -DMATLAB_MEX_FILE /fixed
set OPTIMFLAGS=/MD -Ox -DNDEBUG
set DEBUGFLAGS=/MDd -Zi
set NAME_OBJECT=/Fo

rem
********************************************************************
rem Linker parameters
rem
********************************************************************
set LIBLOC=%MATLAB%\extern\lib\win32\digital\df60
set LINKER=link
set LINKFLAGS=/DLL /EXPORT:_MEXFUNCTION@16 /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%.dll"
set RSP_FILE_INDICATOR=@

rem
********************************************************************
rem Resource compiler parameters
rem
********************************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=
-----------------------------------------------------------
!
! Program Celsius Table: Prints simple Fahrenheit-Celsius table
!
	program celsius_table
	implicit none
	real Fahrenheit, Celsius

	print *,' Fahrenheit Celsius'	
	print *,'--------------------------'
	do Fahrenheit = 30, 220, 10
		Celsius = (5.0/9.0) * (Fahrenheit-32.0)
		print '(F13.0,F12.3)',Fahrenheit,Celsius
	end do
	end
-----------------------------------------------------------
mark wrote:
>
>
> It looks like your compiler is now setup right. Could you post
> your
> fortran code? It should follow this basic format.
>
> Subroutine mexFunction(nlhs, plhs, nrhs, prhs)
>
> integer nlhs, nrhs
> integer plhs(*), prhs(*)
> C Body
> return
> end
>
> Also, when I first installed my 7.0.4 version, I installed it to a
> custom location whose path had spaces in it. This ended up causing
> errors when trying to run mex. I don't remember exactly what they
> were but you may want to check that too. I fixed it by editing the
> mexopts.bat file, reinstalling to the default location would have
> worked too. You may want to check out that mexopts.bat file anyway
> to make sure the various parameters look correct.
>
> regards
> mark
>
> marcin kujawa wrote:
>>
>>
>> I want to create the mex file from external fortran file
>> (file.for).
>> I use compaq visual fortran 6.6a and matlab v13. Pleas help me.
I
>> have still the same problem.
>> ------------------------------------------------------
>>>> mex -setup
>> Please choose your compiler for building external interface
(MEX)
>> files:
>>
>> Would you like mex to locate installed compilers [y]/n? y
>>
>> Select a compiler:
>> [1] Compaq Visual Fortran version 6.6 in C:\Program
> Files\Microsoft
>> Visual Studio
>> [2] Lcc C version 2.4 in C:\MATLAB6P5\sys\lcc
>> [3] Microsoft Visual C/C++ version 6.0 in C:\Program
>> Files\Microsoft
>> Visual Studio
>>
>> [0] None
>>
>> Compiler: 1
>>
>> Please verify your choices:
>>
>> Compiler: Compaq Visual Fortran 6.6
>> Location: C:\Program Files\Microsoft Visual Studio
>>
>> Are these correct?([y]/n): y
>>
>> The default options file:
>> "C:\Documents and Settings\Administrator\Application
>> Data\MathWorks\MATLAB\R13\mexopts.bat"
>> is being updated from
>> C:\MATLAB6P5\BIN\WIN32\mexopts\df66opts.bat...
>>
>>>> mex cel.f
>> Creating library _lib4119.lib and object _lib4119.exp
>> _lib4119.exp : error LNK2001: unresolved external symbol
>> _MEXFUNCTION@16
>> cel.dll : fatal error LNK1120: 1 unresolved externals
>>
>> C:\MATLAB6P5\BIN\WIN32\MEX.PL: Error: Link of 'cel.dll' failed.
>>
>> ??? Error using ==> mex
>> Unable to complete successfully
>> ------------------------------------------------------
>> thx
0
markuj (10)
8/27/2005 7:56:12 AM
markuj wrote:
> This is my mexopts.bat file. Is it correct?
> I send you my hypothetical fortran code too.

* snip mexopts.bat *
> -----------------------------------------------------------
> !
> ! Program Celsius Table: Prints simple Fahrenheit-Celsius table
> !
> 	program celsius_table
> 	implicit none
> 	real Fahrenheit, Celsius
> 
> 	print *,' Fahrenheit Celsius'	
> 	print *,'--------------------------'
> 	do Fahrenheit = 30, 220, 10
> 		Celsius = (5.0/9.0) * (Fahrenheit-32.0)
> 		print '(F13.0,F12.3)',Fahrenheit,Celsius
> 	end do
> 	end
> -----------------------------------------------------------
> mark wrote:
> 
>>
>>It looks like your compiler is now setup right. Could you post
>>your
>>fortran code? It should follow this basic format.
>>
>>Subroutine mexFunction(nlhs, plhs, nrhs, prhs)
>>
>>integer nlhs, nrhs
>>integer plhs(*), prhs(*)
>>C Body
>>return
>>end


Did you even read mark's post?  You should also consult the mathworks 
External Interfaces Documentation.  As mark pointed out, you need the 
SUBROUTINE MEXFUNCTION
END SUBROUTINE

Also, I don't think you'll be able to use print from your mex functions. 
  You'll need to use mexPrintf
0
cchgroupmail (818)
8/27/2005 12:53:38 PM
Reply: