Calling Shared Libraries in Deployed Applications
loadlibrary function in MATLAB® allows you to load shared library into MATLAB.
Loading libraries using header files is not supported in compiled applications. Therefore,
to create an application that uses the
loadlibrary function with a header
file, follow these steps:
Create a prototype MATLAB file. Suppose that you call
loadlibrarywith the following syntax.
Run the following command in MATLAB only once to create the prototype file:This creates
loadlibrary(library, header, 'mfilename', 'mylibrarymfile');
in the current folder. If you are on Windows®, another file named
library_thunk_pcwin64.dllis also created in the current folder.
Change the call to
loadlibraryin your MATLAB to the following:
Compile and deploy the application.
If you are integrating the library into a deployed application, specify the library’s
library_thunk_pcwin64.dll, if created, using the
mcccommand. If you are using Application Compiler or Library Compiler apps, add the
.dllfiles to the Files required for your application to run section of the app.
If you are providing the library as an external file that is not integrated with the deployed application, place the library
.dllfile in the same folder as the compiled application. If you are on Windows, you must integrate
library_thunk_pcwin64.dllinto your compiled application.
The benefit of this approach is that you can replace the library with an updated version without recompiling the deployed application. Replacing the library with a different version works only if the function signatures of the function in the library are not altered. This is because
library_thunk_pcwin64.dllare tied to the function signatures of the functions in the library.
You cannot use
loadlibrary inside MATLAB to load a shared library built with MATLAB. For more information on
loadlibrary, see Limitations to Shared Library Support.
Operating systems have a
loadlibrary function, which loads
specified Windows operating system module into the address space of the calling