MEX files do not work on a network drive on Windows

I am trying to develop MEX files using the IDE within Microsoft Visual Studio 2022. I am using the templates provided by https://marketplace.visualstudio.com/items?itemName=gharveymn.MEXFunctionTemplates. I am starting with a simple MEX file - I have tried "C:\Program Files\MATLAB\R2024a\extern\examples\cpp_mex\arrayProduct.cpp" and "C:\Program Files\MATLAB\R2024a\extern\examples\mex\arrayProduct.c". I successfully build the .mexw64 file and copy it to an empty directory on my C drive. The MEX file works as expected.
However, if instead I copy the .mexw64 file to a network directory and then add that directory to the Matlab path, the MEX file does not work. Matlab seemingly hangs along with the rest of Windows. My only path to recovery is a hard reset via the power button. I have tried mapping the network directory to a drive letter to no avail.
Any suggestions for a fix would be greatly appreciated. I realize I could build these simple MEX files with the mex command in Matlab, but my goal is to next build a MEX file that calls other libraries. Developing within Visual Studio has worked well for me in the past (pre-2017). The ability to provide additional include directories, additional library directories, additional library filenames, etc. within the IDE is valuable. I also have previously been able to perform debugging within VS as well. But right now I can't get even these very basic MEX files to compile without adding the additional stuff in.
Thanks!

7 Comments

I also followed my old method, which used to be provided by the following link (which is now dead): §http://www.mathworks.com/help/matlab/matlab_external/compiling-mex-files-with-the-microsoft-visual-c-ide.html
I get the same behavior: the MEX file works on a local drive but not a network drive.
As I said above, I've also tried the modern C++ interface to MEX files. It also produces files that work on a local drive but not a network drive.
I simplified this to the following:
  1. Start in an empty directory on the local C drive
  2. Copy arrayProduct.cpp from the %matlabroot%\extern\examples\cpp_mex directory to the current directory. (I have previously run mex -setup cpp and Matlab R2024a successfully found MS Visual Studio 2022, the only compiler on my system.)
  3. Run mex arrayProduct.cpp in Matlab
  4. Exit Matlab (probably not necessary)
  5. Copy the .mexw64 file it created to a network drive
  6. Restart Matlab
  7. Add the network location to the Matlab path
  8. Call the MEX file
This hangs Matlab and most of the rest of Windows.
It appears to be an issue with the configuration of the network. I continued troubleshooting:
  1. Installed VS 2019 and saw the same behavior.
  2. Tried a different network location operated by a different IT group. Success! The MEX file works fine from this network location.
If anybody has any suggestions for what I might request of our IT folks or what I might do myself, I'd appreciate it. I'm in over-my-head at this point.
Tough for issues like this from afar, but I'll axe a Q? anyway...were you able successfully map a drive to the problem network? If so, do ordinary m-files on that network work or is it only mex-files? I know MATLAB doesn't deal with network path names gracefully at all, but I've had success mapping drives in Windows...
I had the same thought. I have that network location mapped to my S:\ drive and tried using both the UNC path and the S:\ drive specification to no avail. Ordinary m-files work fine with either the drive letter mapping or the UNC path.
Thanks,
Eric
dpb
dpb on 22 Aug 2024
Edited: dpb on 22 Aug 2024
If your IT folks don't have a klew (which they probably won't given it appears to be MATLAB-specific), I'd suggest submitting an official bug/support request to TMW.
I had a machine crash a while back and haven't yet gotten compilers installed to be able to try a test case with the mapped network drive here and, unfortunately, don't have the time right now to go do that, sorry.
Thanks. I've opened up a support request with TMW.

Sign in to comment.

Answers (1)

Eric
Eric on 29 Aug 2024
Edited: Eric on 29 Aug 2024
With the help of the Mathworks support team I was able to track down the problem. I'm providing the answer here in case it is helpful to others.
This problem exists for certain versions of Matlab R2024a. I cannot speak for earlier versions of Matlab. I learned that the following versions do not work (I'm not sure of the Update number for the first one - the ver command does not provide it):
  • MATLAB Version: 24.1.0.2537033 (R2024a)
  • MATLAB Version: 24.1.0.2628055 (R2024a) Update 4
The following version does work:
  • MATLAB Version: 24.1.0.2689473 (R2024a) Update 6
Unfortunately, obtaining Update 6 can be challenging (e.g., see here). To get Update 6 I needed to get have my corporate IT staff obtain the full ISO from the Mathworks. When the earlier versions were installed and I selected "Check for Updates", the tool reported that no new updates were available.
Best regards,
Eric

Categories

Products

Release

R2024a

Asked:

on 21 Aug 2024

Edited:

on 29 Aug 2024

Community Treasure Hunt

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

Start Hunting!