Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force MATLAB to reload library linked in mex function

Tags:

matlab

mex

I have a Mex-function, say myfunction.mexmaci64 (which is the correct ending on OS X).

Now, myfunction is linked against a library mylibrary.dylib. Both, mex-file and library, reside in the same folder.

Now, whenever I change something in mylibrary, MATLAB does not reload the new library version but instead uses the old one until I do restart MATLAB. That is very anoing when doing development and debugging work. Is there a way to force MATLAB to reload the library without restarting the application?

Note: It would be easy to link the library statically into the mex function. However, as I link the same library across quite a few mex-files, I would prefer to keep my single shared library to reduce compilation times and data redundancy.

Edit:

Concerning the discussion wether the clear mex helps:

[~, loaded_mexes] = inmem('-completenames'); % get canonica

returns a list with all loaded mex-files. This list does not contain the linked library, but only the mex-files itself. Using clear mex successfully empties this list, but does not unload mylibrary - running the mex function again still yields the same output as it did with the old shared library.

like image 608
Thilo Avatar asked Jun 25 '13 11:06

Thilo


2 Answers

To clear a library from memory I usually have excellent luck with

bdclose all;

Then if I'm really feeling militant, I'll do:

bdclose all; % clear all libraries out of memory ( supposedly )
clear all;   % clear all workspace variables, mex, etc. ( supposedly )
rehash;      % cause all .m files to be reparsed when invoked again
like image 182
macduff Avatar answered Oct 24 '22 17:10

macduff


Does clear mex do what you need?

like image 28
Sam Roberts Avatar answered Oct 24 '22 17:10

Sam Roberts