Hi all, I've got some experience with doing standalone cpp programming, but the current project I'm working on involves using Simulink. Up to this point, the simulink model has been calling a .M script, but the number of ODE states are huge, and the program is taking forever to run, so it was time to revamp and move to .cpp.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include "iostream.h"
class organ {
//organ class functions and variables
};//end of organ class definition
//
//Organ class functions
//class function definitions
#ifdef __cplusplus
extern "C" { // use the C fcn-call standard for all functions
#endif // defined within this scope
#define S_FUNCTION_LEVEL 2
#define S_FUNCTION_NAME sepsis_ode_csimcall
#include "simstruc.h"
//S-Function methods go here
#ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
#include "simulink.c" /* MEX-file interface mechanism */
#else
#include "cg_sfun.h" /* Code generation registration function */
#endif
#ifdef __cplusplus
} // end of extern "C" scope
#endif
|
This is the basic backbone of the code, with the actual methods having a bunch of biological things you all probably wouldn't be interested in. When I compile with MATLAB mex I get the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
>> mex sepsis_ode_csimcall.cpp
Error sepsis_ode_csimcall.cpp: 27 syntax error; found `organ' expecting `;'
Error sepsis_ode_csimcall.cpp: 27 syntax error; found `{' expecting `;'
Error sepsis_ode_csimcall.cpp: 27 skipping `{'
Error sepsis_ode_csimcall.cpp: 97 syntax error; found `:' expecting `;'
Error sepsis_ode_csimcall.cpp: 97 skipping `:'
Error sepsis_ode_csimcall.cpp: 100 redeclaration of `organ' previously declared at sepsis_ode_csimcall.cpp 27
Warning sepsis_ode_csimcall.cpp: 100 missing return value
Error sepsis_ode_csimcall.cpp: 104 redefinition of `organ' previously defined at sepsis_ode_csimcall.cpp 100
Error sepsis_ode_csimcall.cpp: 104 redeclaration of `organ' previously declared at sepsis_ode_csimcall.cpp 100
Error sepsis_ode_csimcall.cpp: 110 undeclared identifier `Vdotout'
Error sepsis_ode_csimcall.cpp: 115 undeclared identifier `orgID'
Error sepsis_ode_csimcall.cpp: 131 illegal use of type name `real_T'
Error sepsis_ode_csimcall.cpp: 131 undeclared identifier `x'
Error sepsis_ode_csimcall.cpp: 131 operands of = have illegal types `double' and `pointer to double'
Error sepsis_ode_csimcall.cpp: 131 lvalue required
Error sepsis_ode_csimcall.cpp: 133 syntax error; found `)' expecting `;'
Error sepsis_ode_csimcall.cpp: 133 skipping `)'
Error sepsis_ode_csimcall.cpp: 134 type error: pointer expected
Error sepsis_ode_csimcall.cpp: 136 syntax error; found `}' expecting `)'
Error sepsis_ode_csimcall.cpp: 136 unrecognized statement
Error sepsis_ode_csimcall.cpp: 140 syntax error; found `organ' expecting `;'
Error sepsis_ode_csimcall.cpp: 140 too many errors
C:\PROGRA~1\MATLAB\R2009A\BIN\MEX.PL: Error: Compile of 'sepsis_ode_csimcall.cpp' failed.
|
Now, like I said, I've not delved into this a lot. The MATLAB lcc inclue folder did not initially have the iostream header files, so I copied the headers from the visual studio include folder to the lcc include folder. This included:
iostream.h
ios.h
streamb.h
useoldio.h
istream.h
ostream.h
The old-style header files were used for two reasons: I was afraid the lcc compiler woudln't know what to do with a simple #include <iostream>, as the stock .cpp mex file included the header file. And also because I didn't know which other files were required by <iostream>.
So the problem by my judgement seems to be that the class simply isn't being recognized. Does anyone know a solution for this?