Strange behaviour of loadlibrary() in MATLAB 2023a

8 Ansichten (letzte 30 Tage)
Ivan
Ivan am 11 Sep. 2023
Beantwortet: Ivan am 20 Sep. 2023
Hello,
I am trying to migrate an instrument control script from MATLAB 2019b (9.7.0.1737446 Update 9) to MATLAB 2023a (9.14.0.2337262 Update 5). One of the devices is integrated into MATLAB script by means of loading a *.dll provided by the device manufacturer. The strange thing is that while the library works fine in 2019b in 2023a I was not able to load it.
A bit of details about environment.
Both versions of MATLAB are installed on the same PC and run from the same user profile. I use the same compiler, see outputs below, but I also tried self-installed versions of MinGW setting them explicitely with configuremingw.p provided here.
With MATLAB 2023a I get the following.
>> loadlibrary(libname,hfile,'includepath','C:\IVI_Foundation\VISA\Win64\Include\', 'includepath', 'C:\IVI_Foundation\VISA\Win64\Lib_x64\');
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
Error loading library intermediate output follows.
The actual error is at the end of this output.
*********
Failed to parse type '( __fastcall__ )) tlccs_close ( ViSession vi' original input '( __fastcall__ )) tlccs_close ( ViSession vi '
Found on line 99 of input from line 214 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
Failed to parse type '( __fastcall__ )) tlccs_startScan ( ViSession vi' original input '( __fastcall__ )) tlccs_startScan ( ViSession vi '
Found on line 105 of input from line 268 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
Failed to parse type '( __fastcall__ )) tlccs_startScanCont ( ViSession vi' original input '( __fastcall__ )) tlccs_startScanCont ( ViSession vi '
Found on line 107 of input from line 284 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
Failed to parse type '( __fastcall__ )) tlccs_startScanExtTrg ( ViSession vi' original input '( __fastcall__ )) tlccs_startScanExtTrg ( ViSession vi '
Found on line 109 of input from line 301 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
Failed to parse type '( __fastcall__ )) tlccs_startScanContExtTrg ( ViSession vi' original input '( __fastcall__ )) tlccs_startScanContExtTrg ( ViSession vi '
Found on line 111 of input from line 322 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
Failed to parse type '( __fastcall__ )) tlccs_reset ( ViSession vi' original input '( __fastcall__ )) tlccs_reset ( ViSession vi '
Found on line 141 of input from line 566 of file C:\\Program Files\\IVI_Foundation\\VISA\\Win64\\Include\\TLCCS.h
Error parsing argument for function __attribute__ function may be invalid.
*********
Error using loadlibrary
Building TLCCS_64_thunk_pcwin64 failed. Compiler output is:
C:\ProgramData\MATLAB\SupportPackages\R2023a\3P.instrset\mingw_w64.instrset\bin\gcc -I"C:\IVI_Foundation\VISA\Win64\Include"
-I"C:\IVI_Foundation\VISA\Win64\Lib_x64" -I"C:\Program Files\MATLAB\R2023a\extern\include" -fexceptions
-fno-omit-frame-pointer -I"C:\Users\lab\Documents\scripts" -I"C:\Program Files\IVI_Foundation\VISA\Win64\Include"
"TLCCS_64_thunk_pcwin64.c" -o "TLCCS_64_thunk_pcwin64.dll" -shared
TLCCS_64_thunk_pcwin64.c:33:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_close(ViSessionviThunk(void fcn(),const char *callstack,int stacksize)
^
TLCCS_64_thunk_pcwin64.c:42:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_startScan(ViSessionviThunk(void fcn(),const char *callstack,int stacksize)
^
TLCCS_64_thunk_pcwin64.c:51:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_startScanCont(ViSessionviThunk(void fcn(),const char *callstack,int
stacksize)
^
TLCCS_64_thunk_pcwin64.c:60:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_startScanExtTrg(ViSessionviThunk(void fcn(),const char *callstack,int
stacksize)
^
TLCCS_64_thunk_pcwin64.c:69:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_startScanContExtTrg(ViSessionviThunk(void fcn(),const char *callstack,int
stacksize)
^
TLCCS_64_thunk_pcwin64.c:78:40: error: expected '=', ',', ';', 'asm' or '__attribute__' before ')' token
EXPORT_EXTERN_C long long(__fastcall__))tlccs_reset(ViSessionviThunk(void fcn(),const char *callstack,int stacksize)
Please note, that this behaviour was already reported here
Here are the configuration details I use
>> compil = mex.getCompilerConfigurations
compil =
2×1 CompilerConfiguration array with properties:
Name
Manufacturer
Language
Version
Location
ShortName
Priority
Details
LinkerName
LinkerVersion
MexOpt
>> compil(1)
ans =
CompilerConfiguration with properties:
Name: 'MinGW64 Compiler (C++)'
Manufacturer: 'GNU'
Language: 'C++'
Version: '6.3.0'
Location: 'C:\ProgramData\MATLAB\SupportPackages\R2023a\3P.instrset\mingw_w64.instrset'
ShortName: 'mingw64-g++'
Priority: 'E'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: 'C:\ProgramData\MATLAB\SupportPackages\R2023a\3P.instrset\mingw_w64.instrset\bin\g++'
LinkerVersion: ''
MexOpt: 'C:\Users\lab\AppData\Roaming\MathWorks\MATLAB\R2023a\mex_C++_win64.xml'
In MATLAB 2019 everything works as it should
>> compil = mex.getCompilerConfigurations
>> compil(1)
compil =
2×1 CompilerConfiguration array with properties:
Name
Manufacturer
Language
Version
Location
ShortName
Priority
Details
LinkerName
LinkerVersion
MexOpt
ans =
CompilerConfiguration with properties:
Name: 'MinGW64 Compiler (C++)'
Manufacturer: 'GNU'
Language: 'C++'
Version: '6.3.0'
Location: 'C:\ProgramData\MATLAB\SupportPackages\R2023a\3P.instrset\mingw_w64_MATLAB2019.instrset'
ShortName: 'mingw64-g++'
Priority: 'E'
Details: [1×1 mex.CompilerConfigurationDetails]
LinkerName: 'C:\ProgramData\MATLAB\SupportPackages\R2023a\3P.instrset\mingw_w64_MATLAB2019.instrset\bin\g++'
LinkerVersion: ''
MexOpt: 'C:\Users\lab\AppData\Roaming\MathWorks\MATLAB\R2019b\mex_C++_win64.xml'
and
loadlibrary(libname,hfile,'includepath','C:\Program Files\IVI Foundation\VISA\Win64\Include\', 'includepath', 'C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\');
executes without any errors
I have two questions. The first one is more of curiosity
(i)Can someone explain the difference in loadlibrary behaviour in different versions of MATLAB?
The second one is the real question
(ii)How to make loadlibrary working in MATLAB 2023a?
Thank you in advance for any help
Regards,
Ivan

Akzeptierte Antwort

Ivan
Ivan am 20 Sep. 2023
I submitted a bug report on the issue, and in the case someone else will face the same thing, here is the answer from the technical support. This solution worked for me.
------------------------------
To try and resolve it, could you please try to add the line "#define __fastcall" to your "TLCCS.h" file and attempt to load your library again?
A similar behaviour was observed in the following MATLAB Answers post:
------------------------------
Also, there was a remark that may be very useful
"In the meantime, please note that the "loadlibrary" function is an older feature that is still supported, but no longer enhanced. Based on your use case, you may wish to consider calling your C libraries from the new C++ Interface, which is actively enhanced and maintained:
"
So thanks to the technical support team
Regards,
Ivan

Weitere Antworten (0)

Kategorien

Mehr zu C Shared Library Integration finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by