필터 지우기
필터 지우기

loading library is causing error

조회 수: 8 (최근 30일)
Sami Al-Khayat
Sami Al-Khayat 2017년 4월 8일
답변: Walter Roberson 2017년 9월 15일
I'm trying to use loadlibrary to load a .dll-file with its header file using the command as follows:
loadlibrary('pmDevCtrlInterface','pmDevCtrlInterfaceMain.h','alias','dci');
when I do that MATLAB responds with following error:
Warning: Warnings messages were produced while parsing. Check the functions you intend to use for
correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary
In tfi_libloader (line 1)
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
Type 'SAFEARRAYPtrPtr' was not found. Defaulting to type voidPtrPtr.
Found on line 94 of input from line 169 of file C:\\Users\\Sami\\Documents\\MATLAB\\TFI_dll_tests\\pmDevCtrlInterfaceMain.h
*********
Error using loadlibrary
Building dci_thunk_pcwin64 failed. Compiler output is:
C:\ProgramData\MATLAB\SupportPackages\R2017a\MW_MinGW_4_9\bin\gcc -I"C:\Program
Files\MATLAB\R2017a\extern\include" -fexceptions -fno-omit-frame-pointer
-I"C:\Users\Sami\Documents\MATLAB\TFI_dll_tests" -I"C:\Users\Sami\Documents\MATLAB\TFI_dll_tests"
"dci_thunk_pcwin64.c" -o "dci_thunk_pcwin64.dll" -shared
In file included from dci_thunk_pcwin64.c:27:0:
C:\Users\Sami\Documents\MATLAB\TFI_dll_tests/pmDevCtrlInterfaceMain.h:100:10: error: expected
identifier or '(' before string constant
extern "C" DLL_DECLSPEC dciErrorCode __stdcall dciInit(int LoadDaq);
^
C:\Users\Sami\Documents\MATLAB\TFI_dll_tests/pmDevCtrlInterfaceMain.h:101:10: error: expected
identifier or '(' before string constant
extern "C" DLL_DECLSPEC dciErrorCode __stdcall dciInitialised(void);
^
[...]
The errror message itself is way longer but from that point on it only repeats for every function that the dll-file contains.
I made a copy of the header in which i removed every instance of [extern "C"]. When loading that modified header I only had one error at line 169, so I removed line 169 and tried loading the library again. That time MATLAB crashed.
I've got to mention, that I really don't know much at all about header files and how they work. So basically my quesion now is: Is there a way to make that h-file work or is the cause of the problem maybe something entirely different?
  댓글 수: 1
Philip Borghesani
Philip Borghesani 2017년 4월 12일
Did MATLAB crash on loading the library or your first attempted call with calllib? If the crash is on loading the library then most likely the library is not compatible with matlab or not installed correctly. If you made a call with calllib then tell us what the function parameters are supposed to be (the line from the header file helps here along with the output of libfunctions -full for the function) and how you called it from MATLAB. For any crash posting the stack trace can be helpful.

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

답변 (2개)

Saurabh Gupta
Saurabh Gupta 2017년 4월 12일
It looks like you are using a C++ library with header file that does not use a supported format. Consider modifying your header file as described in the following documentation section.
Alternatively, you may want to consider building a mex file.

Walter Roberson
Walter Roberson 2017년 9월 15일
You are compiling C++ source code with gcc, which is a C compiler. The header file you use must be compilable as C.
You should be protecting the C++ parts of the .h file with #ifdef __cplusplus

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by