Calling Shared Libraries in Deployed Applications
The 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.loadlibrary(library, header)
Run the following command in MATLAB only once to create the prototype file:
This createsloadlibrary(library, header, 'mfilename', 'mylibrarymfile');
in the current folder. If you are on Windows®, another file namedmylibrarymfile.mlibrary_thunk_pcwin64.dllis also created in the current folder.Change the call to
loadlibraryin your MATLAB to the following:loadlibrary(library, @mylibrarymfile)
Compile and deploy the application.
If you are integrating the library into a deployed application, specify the library’s
.dllalong withlibrary_thunk_pcwin64.dll, if created, using the-aoption ofmcccommand. If you are using a compiler app, 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 integratelibrary_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
andmylibrarymfile.mlibrary_thunk_pcwin64.dllare tied to the function signatures of the functions in the library.
Note
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.
Note
Operating systems have a loadlibrary function, which loads
specified Windows operating system module into the address space of the calling
process.