Code covered by the BSD License  

Highlights from
Universal MEX wrapper

Universal MEX wrapper


Thomas (view profile)


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 and  With
%local scoping, only one of these libraries can be in the symbol
%space at a time.  Solution: Use global scoping:
%dl_load(,0); dl_load(,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) depends on BLAS.  The user wants to use deep
%binding to the linked, but the user also wants
%to call BLAS functions from Matlab  Solution:
%dl_load(; dl_load(,0); dl_load(0); 
%(Note: without the last call to set the function handle to the
%resident namespace, BLAS functions resolve to
%4) depends on BLAS.  The user wants functions in
%to use Matlab, but the user wants to call functions from 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