Unload MEX file from MATLAB

8 views (last 30 days)
defunct C7=5F>20
defunct C7=5F>20 on 8 Aug 2013
Commented: JulioLP on 12 Nov 2021
Hi, everybody!
I am writing and debugging a mex file in MATLAB. So every time I recompile it I need to reload it somehow in MATLAB. So far, the only things that works is to restart MATLAB, which is very inconvenient.
The way I tried already:
  1. clear mex (removes the file from [~,m] = inmem('-completenames'), but does not actually unload it)
  2. unloadlibrary 'name' (does not work with mex files)
  3. solution posted here: http://stackoverflow.com/questions/17296668/force-matlab-to-reload-library-linked-in-mex-function , which uses bdclose all; close all; rehash;
Are there any other reciepts, what one can do, or is it impossible?
Edit: After some testing, I really belive it is a problem of using shared libraries. I compiled the following MEX-OpenCV example:
#include <mex.h>
#include <opencv2/opencv.hpp>
void mexFunction( int nlhs, mxArray **plhs, int nrhs, const mxArray **prhs){
mexPrintf("Number of input arguments: %d\n",nrhs);
mexPrintf("OpenCV version: %d.%d\n",CV_MAJOR_VERSION,CV_MINOR_VERSION);
}
if I compile it as
mex -lopencv_core testMEX.cpp
it is not possible to recompile it and use it directly after recompilation in MATLAB. However, if I compile the same code with
mex testMEX.cpp
it is loaded in MATLAB automatically directly after recompilation.
  8 Comments
Alec Jacobson
Alec Jacobson on 10 Jun 2018
Is there any followup to this problem with matlab? I'm suffering the same issue.
JulioLP
JulioLP on 12 Nov 2021
Hi,
I had the same problem. Turns out a simple
clear all
is enough to unload the previous mex file and work with the new one. Not the most elegant solution, but it helps for debugging.

Sign in to comment.

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!