Mex function not updated after recompile

I have a simple mex function, which calls another C++ function from a library. I compile the source with
mex -cxx mymexfunction.cpp -I/some/include -L/some/lib -lmylib
The mylib library is dynamic (.so) and is linked itself against some other libraries (boost, OpenCV and some more).
The problem I am having is that once I have called the function mymexfunction once, it will not get updated when I recompile the source code. I have tried
clear
clear all
clear functions
clear fun('mymexfunction')
munlock('mymexfunction')
unloadlibrary('mymexfunction')
...but nothing helps! I have to restart Matlab in order to be able to see the updated mexfunction. Even if I delete the compiled mex file and recompile, I still get the old version of the mex function (not on disk, but in memory).
All is fine if I don't link against mylib, but I have no idea what could be the culprit that prevents the update. The library is unfortunately too large and too interwoven to remove single modules one by one.
Are there some known conditions which could cause such problems?

댓글 수: 3

Kaustubha Govind
Kaustubha Govind 2011년 8월 9일
Could you try "clear mex" and see if that helps?
Martin
Martin 2011년 8월 10일
Thanks for your suggestion, but unfortunately that does not help either.
Alec Jacobson
Alec Jacobson 2020년 6월 12일
Suffering for the same problem even in 2020a...wish this would be fixed or at least a solution provided.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2011년 8월 10일

0 개 추천

If the mex-file is locked from inside by an mexLock, you have to unlock it from inside also: mexUnlock. You have to trigger this by a special input, e.g. nrhs==0 or similar.

댓글 수: 7

Joseph
Joseph 2019년 7월 5일
I have the same problem using Matlab 2019a under OS X 10.14.5. I tried mexUnlock but it didn't help.
Alec Jacobson
Alec Jacobson 2020년 6월 12일
I don't understand this answer. If my code is not calling mexLock do I still need to call mexLock for matlab to recognize my recompiled mex function?
James Tursa
James Tursa 2020년 6월 12일
If the mex routine is calling mexLock, then I don't think you can clear it from the command line. This is to prevent dangling resources etc. Look in the mex routine documentation to find out the syntax to use for it to unlock itself.
Alec Jacobson
Alec Jacobson 2020년 6월 24일
I'm not current calling mexLock at all in my code, but still suffer from this issue that matlab doesn't recognize the recompiled mex function unless I restart matlab.
James Tursa
James Tursa 2020년 6월 26일
편집: James Tursa 2020년 6월 26일
You clear mex, but it is still showing up as in memory when you use inmem? And you have the source code and you know it is not locking itself?
Alec Jacobson
Alec Jacobson 2021년 7월 17일
correct.
Paul Rötzer
Paul Rötzer 2023년 4월 15일
I struggle the same problem on Matlab 2022b on MacOSX (M1) but only when i compile from "outside" of matlab, i.e. when i use cmake build script. For functions which i build "inside" matlab the update works.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기

질문:

2011년 8월 9일

댓글:

2023년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by