Force MATLAB to reload the library associated with the mex function

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

Now my function is linked to the mylibrary.dylib library. Both mex file and library are in the same folder.

Now, when I change something in mylibrary , MATLAB does not reload the new version of the library, but instead uses the old one until I restart MATLAB. This is very unpleasant when you are working on development and debugging. Is there any way to get MATLAB to reload the library without restarting the application?

Note. It would be easy to link the library statically with the mex function. However, since I am linking the same library to multiple mex file files, I would prefer to keep my single shared library to reduce compilation time and data redundancy.

Edit:

As for the discussion, clear mex helps:

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

returns a list with all downloaded mex files. This list does not contain a linked library, but only mex files. Using clear mex successfully empties this list, but does not mylibrary - re-executing the mex function still gives the same result as with the old shared library.

+6
source share
3 answers

To clear the library of memory, I usually do fine with

 bdclose all; 

Then, if I really feel militant, I will 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 
+4
source

Does clear mex do what you need?

+1
source

You can see which library libraries are loading:

  version('-modules') 

I was successful at unloading the mex file and (in the shared library it depended on) by doing

  version('-modules') % test.mexa64 and test.so appear clear test % clear the mex file version('-modules') % both test.mexa64 and test.so no longer appear. 
0
source

Source: https://habr.com/ru/post/948056/


All Articles