loading library is causing error

13 visualizzazioni (ultimi 30 giorni)
Sami Al-Khayat
Sami Al-Khayat il 8 Apr 2017
Risposto: Walter Roberson il 15 Set 2017
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 Commento
Philip Borghesani
Philip Borghesani il 12 Apr 2017
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.

Accedi per commentare.

Risposte (2)

Saurabh Gupta
Saurabh Gupta il 12 Apr 2017
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 il 15 Set 2017
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

Categorie

Scopri di più su C Shared Library Integration in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by