http://www.ifp.illinois.edu/~nakazato/mathlib.html
Who need this?
(Scenario 1) If you need to write complicated matrix operations in C/C++
You can save your time by using MATLAB Math Library.
(Scenario 2) If you want to call your own MATLAB functions from C/C++
MATLAB compiler translates them into C++ codes.
(Scenario 3) If you need a speed boost of your MATLAB function or M-files
You can use MATLAB compiler to translate your M-files into MEX-files which you can call from Matlab.
Manuals
The manuals are available from MathWorks.
Example codes are available in
/usr/local/matlab6_R12/extern/examples/cppmath
To Begin
You need add specific library to your LD_LIBRARY_PATH
Solaris: /usr/local/matlab6_12/extern/lib/sol2
SGI 64 (such as guinan): /usr/local/matlab5.3.1/extern/lib/sgi64
Example:
# setenv LD_LIBRARY_PATH "/usr/local/matlab6_12/extern/lib/sol2:$LD_LIBRARY_PATH"
Use MBUILD - the easiest way
The easiest way to compile the code is mbuild tool
When you run mbuild for the first time, I recommend you to setup mbuild
# /usr/local/matlab6_R12/bin/mbuild -setup
Then,
# /usr/local/matlab6_R12/bin/mbuild ex1.cpp
That's it !! It's very easy, isn't it?
For Windows
mbuild is in [matlab]\bin\mbuild
, where [matlab] is the location of MATLAB instllation.
Manual Compile
For some situation, mbuild may not work well. In this case, you have to manually compile as shown below. The order to specify libraries is important.
For Solaris
As long as I know, MATLAB Math Library works only with Sun's C++ compilers (CC). It causes error with GNU C++ (g++)
# CC -DSOL2 -DUNIX -DX11 -DNDEBUG -O3 +d ex1.cpp \ -I/usr/local/matlab6_R12/extern/include/cpp \ -I/usr/local/matlab6_R12/extern/include -L/usr/local/matlab6_R12/extern/lib/sol2 \ -lmatpp -lmmfile -lmatlb -lmat -lmx -lnsl -lm
For SGI 64 (guinan)
# CC -64 -LANG:bool -DCOMPILER_HAS_BOOL ex1.cpp \ -I/usr/local/matlab5.3.1/extern/include/cpp \ -I/usr/local/matlab5.3.1/extern/include \ -L/usr/local/matlab5.3.1/extern/lib/sgi64 \ -lmatpp -lmmfile -lmcc -lmatlb -lmat -lmx -lm
NOTE
The directories in this documentation are specific to IFP Lab Workstations in Beckman Institute. You will need to change the file locations depending on your environment. Ask your System Administrator.