Page 1 of 1
Plugin load in Matlab
Posted: Tue Feb 12, 2013 10:04 am
by romleberre
Hi,
I am using a force defined by a plugin and I would like to load a model containing this force in Matlab.
Is-there any way to load the specified plugin library in Matlab?
Thanks for your help
Regards,
Romain
Re: Plugin load in Matlab
Posted: Wed Feb 13, 2013 9:55 am
by aymanh
Hi Romain,
Assuming you have the plugin as a shared library (dll) built with same compiler as OpenSim, then you need to ad the directory that contains it to the "librarypath" in Matlab, and then you can invoke loadlibrray() as documented on the Matlab side.
Hope this helps, and please let me know how it goes.
-Ayman
Re: Plugin load in Matlab
Posted: Tue Feb 19, 2013 5:07 am
by romleberre
Thanks Ayman
Re: Plugin load in Matlab
Posted: Mon Jul 01, 2013 3:11 pm
by bradh
I am trying to do this also: load a custom pluggin library in MATLAB.
I have:
1) Ensured that my mex -setup is:
Compiler: Microsoft Visual C++ 2010
Location: C:\Program Files (x86)\Microsoft Visual Studio 10.0
2) In MATLAB, I then use:
Code: Select all
fullpathToHeader = 'C:\OpenSimWorkspace\CustController\CustController.h';
fullpathToDll = 'C:\OpenSim 3.0.1\plugins\CustController.dll';
loadlibrary(fullpathToDll, fullpathToHeader);
(I also know that the controller works in OpenSim. I am using 32bit MATLAB that works with built in OpenSim libraries.)
When I issue the above, I get the error:
Code: Select all
Error using loadlibrary (line 419)
Failed to preprocess the input file.
Output from preprocessor is:HeroController.h
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\eh.h(27) : fatal error C1189: #error : "eh.h is only for C++!"
I believe this is because loadlibrary is only meant for loading C, not C++.
How do I get custom libraries loaded into MATLAB?
Thanks!
Brad
Re: Plugin load in Matlab
Posted: Tue Jul 02, 2013 11:38 am
by aymanh
Hi Brad,
It may help to know where is the "HeroController.h" file in the error message. Most likely issue:
Per MSDN: "Since eh.h is for exception handling it shouldn't be used in a program compiled as C".
Matlab claims to support mex files compiled as C++ so that should take care of the problem
Please let me know how that goes,
-Ayman
Re: Plugin load in Matlab
Posted: Tue Jul 02, 2013 11:47 am
by bradh
Ayman,
My apologies, that was from me trying this with another custom controller. The message is in fact:
Code: Select all
Error using loadlibrary (line 419)
Failed to preprocess the input file.
Output from preprocessor is:CustController.h
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\eh.h(27) : fatal error C1189: #error : "eh.h is only for C++!"
While MATLAB does allow for MEX of C++, the loadlibrary command only works for C (not C++). Do I need to recompile/mex the custom controller inside MATLAB instead of using the loadlibrary command?
Brad
Re: Plugin load in Matlab
Posted: Fri Jun 13, 2014 9:29 am
by dimitra
Has this been solved? I'm having the same problem: I have built a plugin that works in Opensim but cannot load into Matlab with "loadlibrary" because I get the "eh.h is only for C++!" error (I'm using 32bit Matlab 2013b, Opensim 3.2, Visual Studio 2010).
Thank you!
Dimitra
Re: Plugin load in Matlab
Posted: Tue Jul 08, 2014 2:57 pm
by mengxjchina
dimitra wrote:Has this been solved? I'm having the same problem: I have built a plugin that works in Opensim but cannot load into Matlab with "loadlibrary" because I get the "eh.h is only for C++!" error (I'm using 32bit Matlab 2013b, Opensim 3.2, Visual Studio 2010).
Thank you!
Dimitra
Hi Dimitra,
You should use the "osimPlginDLL.h" instead of the "eh.h" you mentioned when you use "loadlibrary()".
I have achieved this successfully.
Best,
Xiangjie
Re: Plugin load in Matlab
Posted: Wed Nov 09, 2016 10:39 am
by vinhnguyen
You should use the "osimPlginDLL.h" instead of the "eh.h" you mentioned when you use "loadlibrary()"
Could you explain more clearly? Is that related to matlab code or VS C++ code?
Thanks,