Hello
I’m using the Matlab acados interface on Windows, and I’ve run into an issue when trying to recompile acados code in a single Matlab session. After I compile once, anytime I try to compile again I run into the following errors:
C:/ProgramData/MATLAB/SupportPackages/R2020b/3P.instrset/mingw_w64.instrset/bin/../lib/gcc/x86_64-w64-mingw32/6.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot open output file C:\Users\bezzo\Documents\GitHub\MPC_Occluded_Env_2\simulations\cleaned_sim\minimal_example\build\libexample.lib: Permission denied
Error using movefile
Cannot write to destination:
C:\Users\bezzo\Documents\GitHub\MPC_Occluded_Env_2\simulations\cleaned_sim\minimal_example\build\example_ocp_set_ext_fun_dyn_0_impl_dae_fun.mexw64. Use the 'f' option to
override.
Error in ocp_set_ext_fun (line 712)
movefile([file, '.', mexext], fullfile(opts_struct.output_dir, [mex_names{ii}, '.', mexext]));
I tried Matlab’s suggestion to use ‘f’ option in movefile, but this results in a ‘permission denied’ error at the same movefile line.
I believe the problem is that for some reason, Matlab still has files open after the first compilation that shouldn’t be kept open. Because of this, Matlab cannot overwrite the file when I try to recompile. For example, the ‘*_ocp_set_ext_fun_dyn_0_impl_dae_fun.mexw64’ file is kept open by Matlab. Below shows a screen shot of the DLL’s that are kept alive by the Matlab process, showing this file (and others).
I can’t delete the build folder, for the same reason that Matlab is still has these files open. I also tried seeing what files were still open by Matlab using the fopen(‘all’) command, but this returned nothing. I’m guessing this is because MEX has these files open, and not strictly Matlab.
Recompiling works when I quit Matlab, which (I’m guessing) force closes all files open by the Matlab process.
Here is a zip file that contains a minimal example that creates the issue on my computer.
Thanks!
Jacob
P.S. As I was typing out this question, I actually found a workaround in Matlab. The following Matlab command force closes files MEX files that are still open:
clear functions
This allows me to recompile. I decided to post anyway to raise the issue and help anyone else that might have this problem.