9.2 TheMatlabengine library 289
9.2 TheMatlabenginelibrary.....................
The Matlabenginelibrary contains a collection of functions in the form
of an application program interface (API). For an official description, visit:
http://www.mathworks.com/access/helpdesk/help/techdoc/matlabexternal.
The engine interface allows us to startMatlabfrom a C++ program,
establish aMatlabworkspace, transfer data to the workspace, carry out cal-
culations in the workspace, and transfer the results back to the C++ domain.
Technically, the engine functions communicate with the C++ functions by a
separate process using pipes in Unix, and through a component object model
(COM) interface in Windows.
Dependencies and linking
To useMatlab, the C++ code must be compiled and linked with a
number of libraries, header files, and data files implementing theengineinterface
to produce a stand-alone binary executable. TheMatlablibraries
libeng.xx libmx.xx libut.xx
are required, where the suffix xx isso(shared object) in Unix,dll(dynamic
link library) in Windows, anddylib(dynamic library) on Apple computers.
Thelibenglibrary requires (depends on) additional third-party libraries
that support Unicode character encoding and data compression. While the
ASCII code covers the letters of only the English alphabet, the Unicode includes
text and symbols of writing systems from all over the world. The associated
library files must reside in the directory hostinglibmxandlibut.
To ensure proper linking in Windows, we download the Dependency
Walkerutility from:http://www.dependencywalker.com, and then drag and
drop the filematlabroot/bin/win32/libeng.dllinto theDependswindow. On
newer systems, we drop the filematlabroot/bin/win64/libeng.dll.
Assume thatMatlabhas been installed in the/usr/local/matlabUnix
directory. To obtain a list of the required libraries, we navigate to the directory
/usr/local/matlab/bin/glnx86and issue the command:
ldd -d libeng.so
The option-drequests a list of dependencies.