Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
MEX with F2C: not linking a file translated from Fortran to C (MARS model)

Subject: MEX with F2C: not linking a file translated from Fortran to C (MARS model)

From: Roland Neumann

Date: 20 Jan, 2009 17:30:20

Message: 1 of 5

My general aim is to run a Fortran function from Matlab for the validation of my PhD work. This function implements a spline regression model of Friedman's MARS (netlib.org). I started with a conversion to C using the f2c tool(netlib.org). Then I put the mexFunction in the resulting c-file to access it from Matlab. I also added the include mex.h as the first line (before the include f2c.h command which is needed by the conversion tool).

My problem is a failed mex run. With the Fortran libs LIBF77.lib and LIBI77.lib included, I get the output below. I'm really stuck here, seems to have some problems with missing or interfering libs, since it doesn't even knows mxGetValue (though mxGetPr for other variables runs through). Any idea why or how to go around?

Thank you very much, Roland

>> mex MexMars.c -argcheck -v
 This is mex, Copyright 1984-2006 The MathWorks, Inc.
 
-> Default options filename found in C:\Documents and Settings\neumann\Application Data\MathWorks\MATLAB\R2007a
----------------------------------------------------------------
-> Options file = C:\Documents and Settings\neumann\Application Data\MathWorks\MATLAB\R2007a\mexopts.bat
      MATLAB = C:\PROGRA~1\_Rol\Mess\Matlab07
-> COMPILER = lcc
-> Compiler flags:
         COMPFLAGS = -c -Zp8 -I"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup
         OPTIMFLAGS = -DNDEBUG
         DEBUGFLAGS = -g4
         arguments = -DARGCHECK
         Name switch = -Fo
-> Pre-linking commands =
-> LINKER = lcclnk
-> Link directives:
         LINKFLAGS = -tmpdir "." -dll "C:\PROGRA~1\_Rol\Mess\Matlab07\extern\lib\win32\lcc\mexFunction.def" -L"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\lib" -libpath "C:\PROGRA~1\_Rol\Mess\Matlab07\extern\lib\win32\lcc" C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\templib2.obj
         LINKDEBUGFLAGS =
         LINKFLAGSPOST = libmx.lib libmex.lib libmat.lib LIBF77.lib LIBI77.lib
         Name directive = -o "MexMars.mexw32"
         File link directive =
         Lib. link directive =
         Rsp file indicator = @
-> Resource Compiler = lrc -I"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\include" -noregistrylookup -fo"mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
 
 
--> "lcc -DARGCHECK -c -Zp8 -I"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup -FoC:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\MexMars.obj -IC:\PROGRA~1\_Rol\Mess\Matlab07\extern\include -IC:\PROGRA~1\_Rol\Mess\Matlab07\simulink\include -DNDEBUG -DMX_COMPAT_32 MexMars.c"
 
Warning MexMars.c: 10095 missing return value
Warning MexMars.c: 12866 possible usage of tt before definition
Warning MexMars.c: 13046 assignment of pointer to float to pointer to double
Warning MexMars.c: 13099 assignment of pointer to float to pointer to double
Warning MexMars.c: 13100 assignment of pointer to int to pointer to double
Warning MexMars.c: 13101 assignment of pointer to float to pointer to double
Warning MexMars.c: 13103 assignment of pointer to int to pointer to double
Warning MexMars.c: 13027 local `pointer to float pred' is not referenced
Warning MexMars.c: 13026 local `int size' is not referenced
Warning MexMars.c: 13021 local `pointer to float sp2' is not referenced
0 errors, 10 warnings
 
--> "lcc -DARGCHECK -c -Zp8 -I"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup -FoC:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\mwdebug.obj -IC:\PROGRA~1\_Rol\Mess\Matlab07\extern\include -IC:\PROGRA~1\_Rol\Mess\Matlab07\simulink\include -DNDEBUG -DMX_COMPAT_32 C:\PROGRA~1\_Rol\Mess\Matlab07\extern\src\mwdebug.c"
 
Warning C:\PROGRA~1\_Rol\Mess\Matlab07\extern\src\mwdebug.c: 600 missing return value
Warning C:\PROGRA~1\_Rol\Mess\Matlab07\extern\src\mwdebug.c: 628 missing return value
Warning C:\PROGRA~1\_Rol\Mess\Matlab07\extern\src\mwdebug.c: 1088 missing return value
0 errors, 3 warnings
 
--> "lcc -c -Zp8 -I"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\include" -DMATLAB_MEX_FILE -noregistrylookup "C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\mex\lccstub.c" -FoC:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\templib2.obj"
 
    Contents of C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\mex_tmp.rsp:
  C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\MexMars.obj C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\mwdebug.obj
 
 
--> "lcclnk -o "MexMars.mexw32" -tmpdir "." -dll "C:\PROGRA~1\_Rol\Mess\Matlab07\extern\lib\win32\lcc\mexFunction.def" -L"C:\PROGRA~1\_Rol\Mess\Matlab07\sys\lcc\lib" -libpath "C:\PROGRA~1\_Rol\Mess\Matlab07\extern\lib\win32\lcc" C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\templib2.obj -s @C:\DOCUME~1\neumann\LOCALS~1\Temp\mex_8463603B-7A8A-460E-1A9D-C24A3CBFBF28\mex_tmp.rsp libmx.lib libmex.lib libmat.lib LIBF77.lib LIBI77.lib"
 
Writing library for MexMars.mexw32
c:\docume~1\neumann\locals~1\temp\mex_8463603b-7a8a-460e-1a9d-c24a3cbfbf28\mexmars.obj .text: undefined reference to '_mxGetValue'
c:\docume~1\neumann\locals~1\temp\mex_8463603b-7a8a-460e-1a9d-c24a3cbfbf28\mexmars.obj .text: undefined reference to '_max2'
c:\docume~1\neumann\locals~1\temp\mex_8463603b-7a8a-460e-1a9d-c24a3cbfbf28\mexmars.obj .text: undefined reference to '_max3'
 .text: undefined reference to '__imp__floor'
 .text: undefined reference to '__imp___iob'
 .text: undefined reference to '__imp__fprintf'
 .text: undefined reference to '__imp__putc'
 .text: undefined reference to '__imp__exit'
 .text: undefined reference to '__imp___errno'
 .text: undefined reference to '__imp__fseek'
 .text: undefined reference to '_sig_die'
 .text: undefined reference to '__imp__fflush'
 .text: undefined reference to '__imp__free'
 .text: undefined reference to '__imp__remove'
 .text: undefined reference to '__imp__fileno'
 .text: undefined reference to '_isatty'
 .text: undefined reference to '__imp__perror'
 .text: undefined reference to '__imp__ftell'
 .text: undefined reference to '__imp__freopen'
 .text: undefined reference to '_open'
 .text: undefined reference to '_close'
 .text: undefined reference to '__imp__strncmp'
 .text: undefined reference to '_access'
 .text: undefined reference to '_mktemp'
 .text: undefined reference to '__imp__fopen'
 .text: undefined reference to '__imp__rewind'
 .text: undefined reference to '__imp__fread'
 .text: undefined reference to '__imp__fwrite'
 .text: undefined reference to '__imp____mb_cur_max'
 .text: undefined reference to '__imp___isctype'
 .text: undefined reference to '__imp___pctype'
 .text: undefined reference to '__imp__atoi'
 
  C:\PROGRA~1\_ROL\MESS\MATLAB07\BIN\MEX.PL: Error: Link of 'MexMars.mexw32' failed.
 
??? Error using ==> mex at 206
Unable to complete successfully.

Subject: MEX with F2C: not linking a file translated from Fortran to C (MARS model)

From: Roland Neumann

Date: 22 Jan, 2009 09:56:04

Message: 2 of 5

Noone tried to run an fortran program translated with F2C as a mex-File? I might assume that the mex.h and F2c.h includes interfer somehow, redefining variable types different. It would explain why there is an error with unknown symbol _mxGetValue. Any idea?

Subject: MEX with F2C: not linking a file translated from Fortran to C (MARS model)

From: Steven Lord

Date: 22 Jan, 2009 15:03:11

Message: 3 of 5


"Roland Neumann" <software-pca@o2online.de> wrote in message
news:gl9frk$77m$1@fred.mathworks.com...
> Noone tried to run an fortran program translated with F2C as a mex-File? I
> might assume that the mex.h and F2c.h includes interfer somehow,
> redefining variable types different. It would explain why there is an
> error with unknown symbol _mxGetValue. Any idea?

Instead of converting your Fortran code to C and then compiling it as a C
MEX-file, why not just make it a Fortran MEX-file?

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f7667dfi1.html

--
Steve Lord
slord@mathworks.comd

Subject: MEX with F2C: not linking a file translated from Fortran to C (MARS model)

From: Roland Neumann

Date: 24 Jan, 2009 18:06:03

Message: 4 of 5

I tried to circumvent that because of my lacking Fortran skills.

Now I got a compiler running and do the mexfunction. At last everything compiled through but segmentation faulted after the first few parameter tests (got messages from there).

Now I would like to debug the code. How is this possible using Visual Studio? The Inten Visual Fortran9.1 is integrated there. As described in Help I can attach Matlab process there aswell. I loaded .f file in Visual Studio. I mexed it with the -v -g options.

Though it doesn't stop at breakpoints, what did I wrong?

Subject: MEX with F2C: not linking a file translated from Fortran to C (MARS model)

From: Roland Neumann

Date: 28 Jan, 2009 18:17:01

Message: 5 of 5

"Roland Neumann" <software-pca@o2online.de> wrote in message <glflaa$c7p$1@fred.mathworks.com>...

> Though it doesn't stop at breakpoints, what did I wrong?

Just in case someone gets stuck here, it was a firewall problem. I could set a fw rule allowing to inject code from Visual studio to Matlab, then it worked.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us