2

I am installing the MinGW-w64 C/C++ compiler for use in MATLAB 20176b but there is several errors for that. How can install this compiler with all the necessary adjustments to use in Matlab 2016b?

As the first way directly from Matlab:

  1. Downloaded the MinGW-w64 C/C++ compiler for Windows from here: https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c++-compiler

  2. After running true Matlab and approval for installation and installing the packages, it gives an error as:

There was a problem installing the third-party software. To resolve this issue, contact Technical Support

The second approach is to install the MinGW-w64 C/C++ compiler separately and then adjust to use in Matlab. But After installation Matlab doesn't recognize it.

math14
  • 153
  • 1
  • 1
  • 7

1 Answers1

5

The details provided on Matlab not recognizing the MinGW installation are a bit vague, but I'll take a shot at it.

When installing MinGW, the default installation directory is one with spaces in the path (Program Files). For some reason, this is not supported by Matlab (https://www.mathworks.com/help/matlab/matlab_external/compiling-c-mex-files-with-mingw.html):

Do not install MinGW in a location with spaces in the path name. For example, do not use: C:\Program Files\TDM-GCC-64

In my situation, I installed MinGW directly on the C drive. As such, my installation directory has the following layout:

C:\mingw64

  • C:\mingw64\bin
  • C:\mingw64\etc
  • C:\mingw64\*...

Once that is installed, all you need to do is point Matlab to the installation directory, in my case, I need to run the following command:

setenv('MW_MINGW64_LOC','C:\mingw64')

After that, you should be squared away to run the mex compilation command.

acampb311
  • 333
  • 4
  • 11
  • Thanks but the error is: "No supported compiler or SDK was found." – math14 Jul 13 '17 at 12:55
  • @steve What was your eventual MinGW installation directory? What happens when you run: getenv('MW_MINGW64_LOC') – acampb311 Jul 13 '17 at 13:00
  • This is the directory: C:\mingw64 – math14 Jul 13 '17 at 13:13
  • Does that mingw64 directory have the following folders directly inside? share, x86_64-w64-mingw32, bin, etc, include, lib, libexec, licenses, opt – acampb311 Jul 13 '17 at 13:17
  • I downloaded the file " Mingw-builds" from: https://mingw-w64.org/doku.php/download – math14 Jul 13 '17 at 13:41
  • Inside the folder, there is another folder namely: mingw32; those folders you mentioned is inside that with i686-w64-mingw32 instead of x86_64-w64-mingw32. – math14 Jul 13 '17 at 13:43
  • Alright, some thoughts: You need to follow the folder structure I outlined. Get those folders out of the mingw32 and place them directly inside the mingw64 folder. Additionally, it looks like you grabbed the 32 bit version of minGW rather than the 64 bit version. That might work, but I am using the 64 bit version. You might be able to get away with just running `setenv('MW_MINGW64_LOC','C:\mingw64\mingw32'). But I would recommend downloading the 64 bit version. – acampb311 Jul 13 '17 at 13:45
  • Could you mention the correct link for downloading the 64bit version? – math14 Jul 13 '17 at 13:51
  • I don't recall exactly where I grabbed my version. However, I believe that the following link will get you where you need to go: [link](https://sourceforge.net/projects/mingw-w64/files/latest/download) Once you have that just run the regular installation. You should end up with a folder path something like 'C:\Program Files\mingw-w64\x86_64-4.9.2-posix-seh-rt_v4-rev4\mingw64' Copy the mingw64 folder and place it at the root of your drive. – acampb311 Jul 13 '17 at 13:54
  • Thanks @acampb311; it brings two items: mex -setup C++ mex -setup FORTRAN – math14 Jul 13 '17 at 14:06
  • I wanted to use a simple example to check if it is working correctly: http://cs.smith.edu/~nhowe/370/Assign/mexfiles.html but there is an error. – math14 Jul 13 '17 at 14:09
  • The example from above: >> mex 'H:\Projects\Matlab\cc4.cpp' >> bw = (rand(4) > .5); >> cc4(bw) – math14 Jul 13 '17 at 14:10
  • The error: Building with 'MinGW64 Compiler (C++)'. Error using mex cc1plus.exe: sorry, unimplemented: 64-bit mode not compiled in – math14 Jul 13 '17 at 14:12
  • Not sure what exactly that *.cpp file does. I would test using the official Matlab provided example. Try running, `copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'),'.','f')` and then `mex yprime.c` – acampb311 Jul 13 '17 at 14:15
  • I used the official example; when I wanted to use `mex yprime.c` then there is an error: `Building with `'MinGW64 Compiler (C)'`. Error using mex cc1.exe: sorry, unimplemented: 64-bit mode not compiled in` – math14 Jul 13 '17 at 14:25
  • Okay, I think the purposes of the original question have been met, Matlab and MinGW are talking. It looks like the problem now could be the options in the MinGW installation process see the following link: (https://stackoverflow.com/questions/38589886/sorry-unimplemented-64-bit-mode-not-compiled-in) – acampb311 Jul 13 '17 at 14:31