Plugin load in Matlab

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Romain LEBERRE
Posts: 12
Joined: Fri Feb 24, 2012 11:47 am

Plugin load in Matlab

Post by Romain LEBERRE » Tue Feb 12, 2013 10:04 am

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

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Plugin load in Matlab

Post by Ayman Habib » Wed Feb 13, 2013 9:55 am

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

User avatar
Romain LEBERRE
Posts: 12
Joined: Fri Feb 24, 2012 11:47 am

Re: Plugin load in Matlab

Post by Romain LEBERRE » Tue Feb 19, 2013 5:07 am

Thanks Ayman

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: Plugin load in Matlab

Post by Brad Humphreys » Mon Jul 01, 2013 3:11 pm

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

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Plugin load in Matlab

Post by Ayman Habib » Tue Jul 02, 2013 11:38 am

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

User avatar
Brad Humphreys
Posts: 79
Joined: Thu Feb 03, 2011 11:32 am

Re: Plugin load in Matlab

Post by Brad Humphreys » Tue Jul 02, 2013 11:47 am

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

User avatar
Dimitra Blana
Posts: 17
Joined: Thu Jul 24, 2008 11:59 am

Re: Plugin load in Matlab

Post by Dimitra Blana » Fri Jun 13, 2014 9:29 am

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

User avatar
Xiangjie Meng
Posts: 15
Joined: Wed Sep 05, 2012 8:09 pm

Re: Plugin load in Matlab

Post by Xiangjie Meng » Tue Jul 08, 2014 2:57 pm

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

User avatar
Vinh Nguyen
Posts: 21
Joined: Fri Sep 26, 2014 8:53 pm

Re: Plugin load in Matlab

Post by Vinh Nguyen » Wed Nov 09, 2016 10:39 am

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,

POST REPLY