How to Compile MATLAB C++ Math Library

http://www.ifp.illinois.edu/~nakazato/mathlib.html

RedPin 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.

RedPin Manuals

The manuals are available from MathWorks
Example codes are available in 

/usr/local/matlab6_R12/extern/examples/cppmath

RedPin 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"

RedPin 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.

RedPin 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

RedPin 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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值