Undefined function or variable 'fid' , but 'fid' isn't in any of the script files

Have created a Matlab generated DLL that is called from a Visual Studio 2010 C++ application. There are 4 M files (written by an ex co-worker 10 years ago) that are compiled for the DLL ; there is no variable or function named 'fid' in any of them. At run time, I catch a mwException after the call to the DLL, and the exception.what() shows "Undefined function or variable 'fid' ".
I'm sorry that I can't show the M files (it's proprietary code in a competitive market) but 'fid' is not in any of them, or even in the C++ application itself.
Not much to go on, I'm afraid - I was just hoping that somebody might have a suggestion for someone new to Matlab. Thanks.

답변 (2개)

C.J. Harris
C.J. Harris 2011년 8월 16일
The variable 'fid' is usually associated with file reading. You might want to start your search at those points in the code where you either open or close an external file (such as a txt/dat file).

댓글 수: 1

Thanks Chris. I actually did check that when I had an 'aha' moment but the two fopen's are :
FILE* pFile = fopen(sFileName,"wt");
FILE* f_lev = fopen (sLevCrFil, "wb");
Since the application compiled and ran fine before the Matlab DLL was added, I had assumed that the undefined function/variable had to be in the M files which is not the case. I'm also wondering now if I have caught the correct error message. Could it be a red herring?
try { Do_Work( nargout ,
mxMatlab_LSts,
mxMatlab_DegSts,
mxMatlab_ExSet,
mxMatlab_RMS,
(mwArray)Matlab_CD_Op,
(mwArray)Matlab_Cr_D,
(mwArray)Matlab_CurvOp,
(mwArray)Matlab_Cr_C,
(mwArray)Matlab_SigT,
(mwArray)Matlab_UB_Model,
(mwArray)Matlab_FNo,
(mwArray)Matlab_LTimes,
(mwArray)Matlab_Hng) ;
}
catch( mwException& e2 )
{
csMess.Format("\n ERROR in DLL \n %s \n", e2.what() ) ;

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 8월 16일
Possibly "fid" is being constructed as a variable name and used in an eval() or feval() statement.
If .fig files are involved somewhere, the reference to "fid" could be buried in some property of a graphic, such as a callback.
The error message you see would be consistent with the possibility that some routine with a parameter named "fig" is being passed too few arguments.
Does diary() work in DLL's, I wonder?

댓글 수: 6

Sudden left turn at Albuquerque here...thanks Walter, this sounds promising.
One of the M files has
if 0;
figure(78); subplot(2,1,1); plot(ResidNorm, SemiNorm, 'o');
title('Smallness constraint L-Curve'); xlabel('ResidNorm'); ylabel('SemiNorm');
subplot(2,1,2); plot(ArcLength, Curvature, 'o'); hold on; plot(x2, y2); hold off;
...
Since I don't need any graphics for my purposes, I'll remake the DLL minus the graphics and see what happens.
Is there a way to determine the buried graphics variables beforehand?
If you are not using a .fig file via openfig() or load(), and if you do not use the relatively new refreshdata() call, then graphics is _probably_ not the problem (but I would not rule it out.)
In the parts you happen to show, there is nothing that would trigger the graphics related possibilities I described earlier. Especially as it is effectively commented out via the "if 0".
Walter, I've run out of obvious solutions awhile ago (given my lack of Matlab knowledge) so any possibilities are very welcome.
I wasn't sure how the Matlab compiler would handle things like 'if 0' - that part of the code obviously wouldn't be performed at run-time - but would it reserve address space anyways ?
Re-created the DLL without any of the graphics , and am still getting the error message "Undefined function or variable 'fid' ".
I think now I'm going to create the DLL with one M file at a time and see if that tells me anything.
Whether or not the compiler generated code for the "if 0" section, it would never _execute_ that code, so nothing in that code could have an effect.
I think what I would suggest at this point is to use the dependency analysis tool, and read through the results carefully looking for calls to routines you do not expect to be called, such as calls to something in a local library where you are expecting the MATLAB library to be called instead.
Thanks Walter, seems to be the only way to go.
Is there any way to squeeze any more information out of the error message? Or is there a way to generate some sort of run-time log out while in the Matlab DLL? You mentioned diary() previously - but my reference to it says that it only records keystrokes.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

질문:

2011년 8월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by