Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
-
Sina Porsa
- Posts: 99
- Joined: Thu Feb 03, 2011 7:21 pm
Post
by Sina Porsa » Sun Jun 02, 2013 7:00 pm
Hi everyone,
I am trying to create a mex file so that I can call opensim functions from MatLab. My test.cpp file is as below:
Code: Select all
#include "mex.h"
#include <OpenSim/OpenSim.h>
using namespace OpenSim;
using namespace SimTK;
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
// Calculations
}
I have changed the
mexopts.bat file and included these two additional directories:
- C:\OpenSim2.4.0\sdk\include\SimTK\include
- C:\OpenSim2.4.0\sdk\include;
When I type
mex test.cpp in MatLab command line, it returns these errors:
test.cpp
c:\opensim2.4.0\sdk\include\opensim\common\PropertySet.h(124) : warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
c:\opensim2.4.0\sdk\include\opensim\common\PropertySet.h(128) : warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
c:\opensim2.4.0\sdk\include\opensim\common\LoadOpenSimLibrary.h(50) : error C2146: syntax error : missing ';' before identifier 'WINAPI'
c:\opensim2.4.0\sdk\include\opensim\common\LoadOpenSimLibrary.h(50) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\opensim2.4.0\sdk\include\opensim\common\LoadOpenSimLibrary.h(50) : error C2146: syntax error : missing ';' before identifier 'LoadOpenSimLibrary'
c:\opensim2.4.0\sdk\include\opensim\common\LoadOpenSimLibrary.h(50) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\opensim2.4.0\sdk\include\opensim\common\LoadOpenSimLibrary.h(50) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'test.cpp' failed.
??? Error using ==> mex at 222
Unable to complete successfully.
Error in ==> testMex at 8
mex test.cpp
Any ideas how can I solve the problem?
Thanks
Sina
p.s: I have attached the modified mexopts.bat file.
-
Attachments
-
- mexopts.txt
- (3.06 KiB) Downloaded 89 times
-
Ilan Eskinazi
- Posts: 24
- Joined: Fri Mar 19, 2010 5:35 am
Post
by Ilan Eskinazi » Tue Jun 04, 2013 9:21 am
Sina,
I'm not sure if this will help you but I'm attaching an example Matlab command which I use to compile a mex file for my OpenSim application. Perhaps you can adapt it to match your needs.
First cpp file is contains mex function. Other cpp files contains other needed code.
-L indicate library locations
-l indicate libraries themselves
-I indicate include folders
-D indicate preprocessor definitions
Code: Select all
mex SurrogatePluginMex.cpp ANN_TFContactForce.cpp ANN_PFContactForce.cpp...
-L'C:\OpenSim 3.1\sdk\lib'...
-L'C:\Users\eskilan\Documents\testing embbeded coder\Multiset models JW\PF\PFsurrDLL\Release'...
-L'C:\Users\eskilan\Documents\testing embbeded coder\Multiset models JW\TF (correct insert)\TFsurrDLL\Release'...
-losimCommon -losimSimulation...
-losimAnalyses -losimActuators -losimTools...
-lOpenSim_SimTKcommon -lOpenSim_SimTKmath...
-lOpenSim_SimTKsimbody -lSimTKlapack -lpthreadVC2...
-lTFsurrDLL -lPFsurrDLL...
-I'C:/OpenSim 3.1/sdk/include'...
-I'C:/OpenSim 3.1/sdk/include/SimTK/include'...
-I'C:\Users\eskilan\Documents\testing embbeded coder\Multiset models JW\TF (correct insert)\TFsurrDLL\TFsurrDLL'...
-I'C:\Users\eskilan\Documents\testing embbeded coder\Multiset models JW\PF\PFsurrDLL\PFsurrDLL'...
-I'C:\Users\eskilan\Documents\Surrogate everything\Opensim simulation\Matlab API\surrogatePluginMex'...
-DWIN32 -D_WINDOWS -DNDEBUG...
;
-
Sina Porsa
- Posts: 99
- Joined: Thu Feb 03, 2011 7:21 pm
Post
by Sina Porsa » Tue Jun 04, 2013 9:02 pm
Thank you Ilan, it is working now!