Code covered by the BSD License  

Highlights from
Universal MEX wrapper

Universal MEX wrapper

by

 

Call any function in a shared library from Matlab (with some limits on the function signature).

dl_load(libPath, varargin)
function [] = dl_load(libPath, varargin)
%[] = dl_load.m(libPath)
%Set a global symbol-space handle for future calls to
%dl_exec or dl_check.  The input 'libPath' can be a string
%giving the absolute or relative path of the library, or a 
%shared object name that exists in the system LD search path.
%To access the resident symbol space, call with 0.  By default
%deep binding is performed: library dependencies are resolved 
%only by looking "down" the dependency tree.
%
%A method to unload symbols is not provided.  Once a binding 
%is made, it is static throughout the Matlab process.
%Calling this function repeatedly, such as within a loop, will
%lead to memory leaks and must be avoided.
%
%An additional feature is that if called with a second argument 0
%the library will be loaded with shallow binding and global scope. 
%This is to allow fine-grained control over the symbol-space 
%search behavior.  Here are scenarios:
%
%1) User wants to access functions in lib1.so and lib2.so.  With
%local scoping, only one of these libraries can be in the symbol
%space at a time.  Solution: Use global scoping:
%dl_load(lib1.so,0); dl_load(lib2.so,0); dl_load(0);
%
%2) User wants the above scenario, but with deep binding.  
%Solution: First load each library locally with deep binding. Since
%the binding cannot be undone, it will be preserved on promotion to
%global scope.
%
%3) Lib1.so depends on BLAS.  The user wants lib1.so to use deep
%binding to the linked otherBLAS.so, but the user also wants
%to call BLAS functions from Matlab mwblas.so.  Solution:
%dl_load(lib1.so); dl_load(lib1.so,0); dl_load(0); 
%(Note: without the last call to set the function handle to the
%resident namespace, BLAS functions resolve to otherBLAS.so.
%
%4) Lib1.so depends on BLAS.  The user wants functions in lib1.so
%to use Matlab mwblas.so, but the user wants to call functions from
%otherBLAS.so at the same time. Solution: Can't be done at present.
%This could be accomplished by modifying the matlab wrappers to
%expose library handles to the user.


global SO_HANDLE;
SO_HANDLE = dl_load_mex(libPath, varargin{:});

Contact us