MINGWROOT environment variable

By convention, the environment variable MINGWROOT tells the path to the compiler binaries like gcc.exe.

  • MSYS2: MINGWROOT=C:\msys64\mingw64\bin

This variable may be needed to modify the GNU Octave PATH on Windows when using “system()” calls with executables compiled by MinGW. A similar issues exists on Windows with Matlab and Parallel Computing Toolbox, that provides its own mpiexec.

Here’s a function we created to workaround these issues, saved as file modify_path.m

function prepend = modify_path()
% for Octave on Windows, it's necessary to prepend MinGW path
% when running MinGW-compiled executables
% Also, Matlab with Parallel Toolbox MPIEXEC conflicts with system MPIEXEC,
% so excise from Path
%
% a command is then run like
%
% system([prepend, ' ', 'foo.exe'])

prepend = '';

if ~ispc, return, end

if isoctave && ~isempty(getenv('MINGWROOT'))

  syspath = [getenv('MINGWROOT'), pathsep, getenv('PATH')];
  % setenv('PATH', syspath)  % does not help
  prepend = ['set PATH=', syspath, ' && '];

else

  addons = matlab.addons.installedAddons();
  if ~any(addons.Name == "Parallel Computing Toolbox")
    return
  end

  path_orig = split(getenv('PATH'), ';');
  i = contains(path_orig, 'MATLAB');  % Matlab's MPIexec will fail
  path_new = join(path_orig(~i), ';');

  % setenv('PATH', path_new{1}) % does not help
  prepend = "set PATH=" + path_new{1} + " && ";

end  % if

end % function