calllib crashes Matlab... no error given
古いコメントを表示
Greetings. I am trying to use some functions in a dll, but when I use calllib, Matlab crashes (and closes) without error.
Any idea what is going on?
EDIT: I just noticed that I got a warning(s) when I loaded the library.
Warning: Eval of const expression 10 ][ 1024 failed with error Unmatched right square bracket at (eval 5) line 1, at end of line syntax error at (eval 5) line 1, near "10 ]" Missing right curly or square bracket at (eval 5) line 2, at end of line
The offending line is...
char gnFn[10][1024];
???
16 件のコメント
Jan
2011 年 10 月 14 日
Sounds like a segmentation fault. Do you assume, that somebody can give a useful advice without knowing any details?
Jan
2011 年 10 月 14 日
"char gnFn[10][1024];" is C, EVAL is MATLAB. Do you try to run C-code by using EVAL?!
tlawren
2011 年 10 月 14 日
Kaustubha Govind
2011 年 10 月 14 日
Have you run "mex -setup" before calling loadlibrary? If yes, what compiler did you select?
tlawren
2011 年 10 月 14 日
Kaustubha Govind
2011 年 10 月 14 日
LCC is a C compiler - could you verify if you DLL is a C library or C++ library? loadlibrary uses the C compiler selected using "mex -setup" to parse the symbols - it is likely that you will see error with LCC if you are attempting to load a C++ library.
If you're not sure, I would recommend installing one of the MSVC Express (free) editions supported for your MATLAB version (see http://www.mathworks.com/support/compilers/previous_releases.html) and select that with "mex -setup"
Kaustubha Govind
2011 年 10 月 14 日
Also, make sure that if you're on 64-bit MATLAB, the DLL is also a 64-bit binary (similarly in case if 32-bit).
Chirag Gupta
2011 年 10 月 14 日
What is the actual call to calllib? What is the exact data that you are passing to the function with calllib? Typically crashes like these are due to the fact that the correct data was not passed (data that MATLAB is available to convert to the appropriate C struct
tlawren
2011 年 10 月 14 日
tlawren
2011 年 10 月 17 日
Chirag Gupta
2011 年 10 月 17 日
Can you call using:
>> calllib('MyLib','Func1','test.dat',int32(10))
if integer is an int32!
tlawren
2011 年 10 月 17 日
Philip Borghesani
2011 年 10 月 17 日
MATLAB includes a copy of Perl for its own use on Windows. The warnings you are seeing could cause problems in the future with some calls to the library but are probably not the cause of your current crash. The version of MATLAB you are using does not support two dimensional arrays declared like:
char gnFn[10][1024]
tlawren
2011 年 10 月 17 日
tlawren
2011 年 10 月 18 日
While troubleshooting a similar issue, an option we did not have to pursue (solved the issue by using 2019a instead of MATLAB 2024a) was using a parallel process to run the DLL. If the DLL took a certain amount of time (in our case, 1-2 seconds was enough to know there was a problem), then the parallel process could be killed and move on. At least that was the principle. Maybe someone out there could make that a reality for their issue/workaround.
Another part of the problem was that initially my inputs exceded what the DLL could handle. So the DLL could perhaps have been coded better, but that part at least was my error.
See also
採用された回答
その他の回答 (1 件)
Philip Borghesani
2011 年 10 月 17 日
1 投票
The usual cause of a calllib call causing MATLAB to exit with no stack trace is the use of the wrong calling convention. loadlibrary defaults to cdecl but many 32 bit libraries are built with stdcall as the default calling convention.
Another is to modify the c header file to properly state the calling convention and rebuild if needed.
3 件のコメント
tlawren
2011 年 10 月 17 日
tlawren
2011 年 10 月 17 日
Philip Borghesani
2011 年 10 月 19 日
Without more information is unlikely that we can help you. The amount of information needed probably belongs in a tech support call not this area.
Needed information
# Matlab version
# copy of header file
# copy of DLL
# full text/error output from your call to loadlibrary and any calllib calls.
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!