Can't use.dll library on the 2020 or later versions of Matlab
14 ビュー (過去 30 日間)
古いコメントを表示
I'm working with some DLL library in order to integrate a measurment instrument (a power meeter) on Matlab. I'm using the 2021 version of Matlab and I used the following code to load the DLL library: (note that the library was given to me from the company who sell me the power meeter).
clear all;
%Load the library
NET.addAssembly('C:\Program Files (x86)\Microsoft.NET\Primary Interop Assemblies\Thorlabs.TLPM_64.Interop.dll');
import Thorlabs.TLPM_64.Interop.*;
%Create a dummy TLPM object to check for compatible devices.
handle = System.IntPtr(0);
device = TLPM(handle);
%Search the device
[~,deviceCount] = device.findRsrc();
When I run it, Matlab load the library but when I try to use the function "findRsrc" I get the following error:
Found on line 1324 of input from line 1065 of file C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\TLPM.h
Type 'intViStatus__fastcall' was not found. Defaulting to type error.
Found on line 1325 of input from line 1066 of file C:\\Program Files\\IVI Foundation\\VISA\\Win64\\Include\\TLPM.h
Warning no reference to header 'C:/Program Files/IVI Foundation/VISA/Win64/Include/visa' added with addheader was found in source.
*********
Error using loadlibrary
Building TPLM_64_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\IVI Foundation\VISA\Win64\Lib_x64\msc" -I"C:\Program Files\IVI Foundation\VISA\Win64\Include" -I"C:\Program
Files\MATLAB\R2020a\extern\include" /Zp8 /W3 /nologo -I"C:\Users\install\Desktop" -I"C:\Program Files\IVI Foundation\VISA\Win64\Include"
"TPLM_64_thunk_pcwin64.c" -LD -Fe"TPLM_64_thunk_pcwin64.dll"
TPLM_64_thunk_pcwin64.c
TPLM_64_thunk_pcwin64.c(47): error C2059: syntax error: '*'
I tried many things ans then, by seraching online, I saw that the problem is may due to the compiler version. Since I have also 2019 and 2020 matlab licenes I tried on both the version and i found out that it works on the 2019 version of Matlab.
So my questions is: Do you have any ideaa what could be the problem on the newest version? there is something that I can do to make it work on the 2020/2021 version?
1 件のコメント
Luke
2025 年 1 月 13 日
I encountered the same situation on the 2022a version, Have you solved this problem?
回答 (1 件)
Satwik
2025 年 1 月 16 日
Hi,
The 'loadlibrary' function is only able to load libraries that are callable from C and whose header files can be parsed by a C compiler. This limitation is mentioned in the documentation given below:
The 'error C2059: syntax error:' commonly occurs when the compiler interprets the header to be a C file when it actually is a C++ file. Here are two possible workarounds to this issue:
1. Allow the header file to be compiled via both a C and C++ compiler using conditional compilation. This is accomplished by including the following lines of code with the exported function declarations:
#ifdef __cplusplus
extern "C" {
#endif
<declarations for exported functions>
#ifdef __cplusplus
}
#endif
This causes the specifier 'extern "C"' to only be included in the header file when it is being processed by a C++ compiler.
2. If it is not possible to re-build the DLL, try modifying the header to make it compatible with the compiler. This may be achieved by one the two ways given below:
i. Change the header file so that it's extension is .HPP instead. This indicates to the compiler that the header file is in C++.
ii. Remove the 'extern "C"' keyword in the header file, since it is not needed when compiling in C.
The following MATLAB answer thread addresses a similar issue based on the error 'C2059: syntax error:' while using 'loadlibrary':
I hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!