Error using loadlibrary line 440

6 views (last 30 days)
Kons Tsak
Kons Tsak on 15 Jun 2016
Edited: Kons Tsak on 16 Jun 2016
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 Comments
Walter Roberson
Walter Roberson on 15 Jun 2016
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 on 15 Jun 2016
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

Sign in to comment.

Accepted Answer

Kons Tsak
Kons Tsak on 16 Jun 2016
Edited: Kons Tsak on 16 Jun 2016
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.

More Answers (1)

Philip Borghesani
Philip Borghesani on 15 Jun 2016
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 Comment
Kons Tsak
Kons Tsak on 16 Jun 2016
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.

Sign in to comment.

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!