supyo
supyo

Reputation: 3037

Matlab add native libraries to path programmatically

Background

I have a Matlab codebase (or App now with r2012b), that I distribute to users.

This app uses JNI with native libraries (several .dll files). On my local machine, this requires entries in a librarypath.txt or javalibrarypath.txt (r2012b) file, as described by Mathworks and Undocumented Matlab.

Question

Is there any way to add native libraries to the Matlab java class path programmatically?

I would like to write an initMyLibrary.m script, whereby:

Any ideas?

Upvotes: 3

Views: 870

Answers (1)

reverse_engineer
reverse_engineer

Reputation: 4269

this might be messy and I'm not an expert in the matter, but wouldn't something like this work in your initMyLibrary.m:

currentdir = pwd; % or any other directory you know the dll will be in
if ispc
    system(['setx path "%path%;' currentdir '"']); % only works from windows 7 onwards though, for xp or vista youll have to change the registry with reg
elseif isunix
    system(['export PATH=$PATH:' currentdir]); % dont know if this works without admin rights though...
elseif ismac
    % for mac I dont know how to do this without admin rights
else
    error('whatever') % error handling
end

Because I think if your dll is on the system path this should be fine no? Don't forget to restore the path at the end of the application.

Anyway all of this might be a little dangerous...

Upvotes: 0

Related Questions