Matlab C Library Installation (or Setup)
| Table of Contents |
Introduction
Matlab provides C and Fortran interfaces to access their built-in functions. These interfaces are usually used to connect C (or Fortran) and matlab, but we can also use them just as a library such as OpenCV or OpenGL libraries in C.
Windows
Installation
Install Matlab. Assume matlab was installed at C:\Program Files\MATLAB\R2007b
Setup MS Visual C++
I write details based on MS Visual Studio 2005. Follow menus of MS Visual C++ window as:
- Tools > Options > Projects and Solutions > VC++ directories >
- Show Directory for: > Include Files. Now add
C:\Program Files\MATLAB\R2007b\extern\include
- Show Directory for: > Library Files. Now add
C:\Program Files\MATLAB\R2007b\extern\lib\win32\microsoft
Choose appropriate msvcXX directory by finding your MS VC++ version.
Setup MS Visual C++ for each project
- Right Click Project > Property >
- Configuration Proeperties > Linker > Input > Additional Dependencies. Now add
- libdflapack.lib libmat.lib libmwservices.lib libeng.lib libmex.lib libmx.lib libfixedpoint.lib libmwlapack.lib libut.lib mclcom.lib mclcommain.lib mclmcr.lib mclmcrrt.lib mclxlmain.lib
- Change 'Configuration' drop down menu from Release (Debug) to Debug (Release).
- Do the same thing (Add .libs to Input)
Or, add below codes into your source codes above #include(s).
#ifdef _MSC_VER #pragma comment(lib, "libdfblas.lib") #pragma comment(lib, "libdflapack.lib") #pragma comment(lib, "libemlrt.lib") #pragma comment(lib, "libeng.lib") #pragma comment(lib, "libfixedpoint.lib") #pragma comment(lib, "libmat.lib") #pragma comment(lib, "libmex.lib") #pragma comment(lib, "libmwblas.lib") #pragma comment(lib, "libmwlapack.lib") #pragma comment(lib, "libmwmathutil.lib") #pragma comment(lib, "libmwservices.lib") #pragma comment(lib, "libmx.lib") #pragma comment(lib, "libut.lib") #pragma comment(lib, "mclcom.lib") #pragma comment(lib, "mclcommain.lib") #pragma comment(lib, "mclmcr.lib") #pragma comment(lib, "mclmcrrt.lib") #pragma comment(lib, "mclxlmain.lib") #endif
Typically,
#ifdef _MSC_VER #pragma comment(lib, "libmat.lib") #pragma comment(lib, "libmx.lib") #endif
are enough to use matlab C Library. Add
#pragma comment(lib, "libmex.lib")
if you are supposed to create mex (creation of matlab functions in C). Add
#pragma comment(lib, "libeng.lib")
if you are supposed to use matlab engine (Run matlab process in background to make matlab do computation and receive results seamlessly). Add
#pragma comment(lib, "mclmcr.lib")
if you are supposed to use compiled matlab file in C.
Header Files
#include "matrix.h" #include "mat.h"
Mex
#include "mex.h"
Matlab engine
#include "engine.h"
Matlab compiler
#include "mclmcr.h"
