Error using loadlibrary line 440

10 次查看(过去 30 天)
Hello. I am trying to connect an EPOS controller with Matlab through a .dll file. I use Matlab function loadlibrary('EposCmd64.dll','Definitions.h') and keep getting the same error
Error using loadlibrary (line 440)
Building EposCmd_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2014b\extern\include" /W3 /nologo -I"C:\Program
Files\MATLAB\R2014b\extern\include" -I"C:\Program Files\MATLAB\R2014b\simulink\include"
/D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0
-I"C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con"
-I"C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con" "EposCmd_thunk_pcwin64.c" -LD
-Fe"EposCmd_thunk_pcwin64.dll"
EposCmd_thunk_pcwin64.c
C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con\Definitions.h(121) : error C2059: syntax
error : 'string'
The last line keeps on repeating for the rest lines of 'Definitions.h' . I have searched and tried almost everything so far. I have the Microsoft Visual Studio C++ 2015 SDK so I believe I have all the necessary stuff. Also, I can't create MEX files because the functions are too many to create!
Thanks in advance, Konstantinos
  2 个评论
Walter Roberson
Walter Roberson 2016-6-15
Are you trying to use the C++ "string" datatype in the interface? Your .c file implies you are using C rather than C++, and you could have problems if you try to mix the two.
Kons Tsak
Kons Tsak 2016-6-15
In the 'Definitions.h' header there is no use of the type "string". However it does occure an error. This is also something that puzzles me. I have done #include < string.h > but it didn't make any difference. I attach the header file. The problem occurs at function call
//Communication
Initialisation_DllExport HANDLE __stdcall VCS_OpenDevice(char* DeviceName, char* ProtocolStackName, char* InterfaceName, char* PortName, DWORD* pErrorCode);
and keeps on going at almost every single line after that.
Thank you

请先登录,再进行评论。

采纳的回答

Kons Tsak
Kons Tsak 2016-6-16
编辑:Kons Tsak 2016-6-16
Finally I found a correct .zip that worked fine. You can find it here http://www.mathworks.com/matlabcentral/fileexchange/53735-commanding-maxon-motors-epos2-motor-controller-from-matlab. I had already seen this one but hadn't undestand that I could actually download some file etc. Still new at Matlab. I also attach the correct 'Definitions.h' file for any future reference. In general, the "extern C" is not necessary here, in fact it does cause the loadlibrary to produce errors.

更多回答(1 个)

Philip Borghesani
Philip Borghesani 2016-6-15
The header file as written is not compatible with C code only c++. On first inspection It looks like the dll might be callable from c and usable with loadlibrary but the header will need to be fixed.
The basic problem is the definitions that look like:
#define Initialisation_DllExport extern "C" __declspec( dllexport )
and there use. The simplest fix to get loadlibrary working would be to remove all references to these defines from the code they are not needed for loadlibrary.
  1 个评论
Kons Tsak
Kons Tsak 2016-6-16
I commented out the #define lines as you suggested but I got some new errors like
Error using loadlibrary (line 440)
Building EposCmd64_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2014b\extern\include" /W3 /nologo -I"C:\Program
Files\MATLAB\R2014b\extern\include" -I"C:\Program Files\MATLAB\R2014b\simulink\include"
/D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0
-I"C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con"
-I"C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con" "EposCmd64_thunk_pcwin64.c" -LD
-Fe"EposCmd64_thunk_pcwin64.dll"
EposCmd64_thunk_pcwin64.c
C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con\Definitions.h(123) : error C2054: expected
'(' to follow 'Initialisation_DllExport'
C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con\Definitions.h(123) : error C2085:
'VCS_OpenDevice' : not in formal parameter list
C:\Users\Konstantinos\Desktop\Thesis\MAT_epos_con\Definitions.h(124) : error C2061: syntax
error : identifier 'Initialisation_DllExport'
The 3 types of error also continue for the next lined as well. Searching the web I have found similar cases. It seems I need to edit the header file so as to be C compatible for Matlab.
Thank you for your response. If you have any further suggestions I would be more than grateful.

请先登录,再进行评论。

类别

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