Install MinGW-w64 Compiler - MATLAB2013a or 2016a - matlab

the adds-on explorer doesn't work as it needs a renewal license ... Is there anyway I can install the compiler to use a "mex -setup" command ?

The instructions below will work on Windows 7 64 bit machine, for Matlab R2016Aa:
System Requirements
-Windows 7 64 bit
-Matlab R2016a
In order to be able to use LIBSVM package you need to have a C compiler installed on your system.
How to install MinGW-w64 Compiler
-In Matlab go to ENVIRONMENT section under the HOME tab
-Click on Add-Ons > Get Add-Ons
-Select Features from left pane under Filter by Type
-Click MinGW-w64 tdm-gcc
-Click install
-Support Package Installer window will pop up
---Get the URL - MinGW-w64 Runtime http://sourceforge.net/projects/tdm-gcc/files/Sources/TDM%20Sources/
--Download the executable
--Make sure there is no space in the folder where you will download the compiler
--Once the installation is completed, you should have a folder under C drive with a name TDM-GCC-64
-Set Environment Variables in Windows
-Right click on Computer
-Left click Properties
-Click Advanced System Settings
-Click Environment Variables
-Click New under System Variables
-Enter MW_MINGW64_LOC as Variable name
-Enter C:\TDM-GCC-64 as the path (you installed compiler)
-Click OK
-In Matlab
-Set the current folder to Documents>MATLAB>Libsvm-3.2.2>matlab folder
-Test Compiler using yprime.c file
-Type copyfile(fullfile(matlabroot,'extern','examples','mex','yprime.c'),'.','f')
-Set Environment in Matlab using the following command
YOU DO THIS EVERY TIME YOU START MATLAB AND WANT TO USE LIBSVM LIBRARY
setenv('MW_MINGW64_LOC','C:\TDM-GCC-64')
Type make
Type mex -setup (to choose suitable compiler for mex) You should get something like this:
MEX configured to use 'MinGW64 Compiler (C)' for C language
compilation. Warning: The MATLAB C and Fortran API has changed to
support MATLAB variables with more than 2^32-1 elements. In the
near future you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following: mex
-setup C++ mex -setup FORTRAN
-Type mex yprime.c You should get the following result: Building with 'MinGW64 Compiler (C)'. MEX completed successfully.
-Test the compiler
yprime(1,1:4) You should get the following ans =
2.0000 8.9685 4.0000 -1.0947
-Type make to build mex files for libvm read write and others.
-You may get the following error initially:
make Building with 'MinGW64 Compiler (C)'. Error: C:\MATLAB\SupportPackages\R2016a\libsvm-3.22\matlab\make.m failed
(line 13) gcc: error: -fexceptions: No such file or directory
-To resolve this issue, open make.m file and change CFLAGS= to COMPFLAGS, save it and call it again.
-Successful installation will show the following
make Building with 'MinGW64 Compiler (C)'. MEX completed successfully. Building with 'MinGW64 Compiler (C)'. MEX completed
successfully. Building with 'MinGW64 Compiler (C++)'. MEX completed
successfully. Building with 'MinGW64 Compiler (C++)'. MEX completed
successfully.

Related

use library (gcc) in matlab and error with compile of mex

I am using Mac OSX (yosemite V 10.10.1) and running MATLAB 2014a on it.
I wanted to use SPAM library (sparse modeling software by J. Mairal) on MATLAB and for that I have to install XCode6.1 (that has gcc). First I type in command window mex -setup and result is shown below:
mex -setup
MEX configured to use 'Xcode with Clang' for C language compilation.
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the
new API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html.
To choose a different language, select one from the following:
mex -setup C++
mex -setup FORTRAN
So after that I run the compile.m file in SPAM library and suddenly I saw an error that was:
add_flag =
-mmacosx-version-min=10.6
Warning: Directory already exists.
> In compile at 144
compilation of: -I./linalg/ -I./decomp/ -I./prox/ -I./dictLearn/ dictLearn/mex/mexArchetypalAnalysis.cpp
Building with 'Xcode Clang++'.
clang: warning: argument unused during compilation: '-fopenmp'
Error using mex
ld: warning: directory not found for option '-L/usr/lib/gcc/x86_64-linux-gnu/4.8/'
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in compile (line 439)
mex(args{:});
I don't understand what to do. please help me!
It appears that the actual error is occurring at the point of linking with precompiled libraries. The 2 issues are as follows:
The compile code apparently included in the compile.m file looks like it is intended to compile with gcc (it is trying to include files installed by GCC, possibly even linux-specific ones, are you sure that it's an OSX-compatible toolbox?), and yet the error strongly suggests that you are in fact using clang to compile it - you will either need to change the compiler (easy) or rewrite compile.m (not so easy).
One of the libraries that the code needs to have installed in order to be properly linked hasn't been found. On OSX I think this file should be called libgomp.dylib (any mac afficionados want to confirm this?). If you have it on your computer, then it's not in a directory that clang is looking in. You can confirm the library is installed by running find / | grep libgomp.dylib from the terminal - if it is there, you can add it into the compiler argument in compile.m using the -I /DIRECTORY_HOLDING_LIBRARY syntax.
It is entirely possible that fixing 1. will also remediate 2. - I have never tried using SPAM

MATLAB can't see my C compiler to mex svmlib

I have 64-bit Mac, OS X 10.8.5, and I have xcode installed. I can also verify gcc works from the command line. When I type mex -setup I get
The options files available for mex are:
1: /Applications/MATLAB_R2013a.app/bin/mexopts.sh :
Template Options file for building MEX-files
0: Exit with no changes
This is unhelpful. And when I type make, with all of the relevant libsvm files in my folder of choice, I get
make
xcodebuild: error: SDK "macosx10.7" cannot be located.
xcrun: error: unable to find utility "clang", not a developer tool or in PATH
mex: compile of ' "libsvmread.c"' failed.
If make.m fails, please check README about detailed instructions.
Is anyone able to help me with this?
The quickest thing is to edit the mexopts.sh file directly, using your favorite text editor (you may need to do this with "Administrator Privileges"). The file:
/Applications/MATLAB_R2013a.app/bin/mexopts.sh
defines a bunch of paths and flags for invoking the C/C++ compiler on your system. It tends not to keep up with revisions to the MacOS.
On my system, I had to make the following changes:
lines 258-260
CC='gcc'
SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'
MACOSX_DEPLOYMENT_TARGET='10.6'
line 273
CXX=g++
There will be many references to "CC=" in the file; you're looking for the ones that follow the line
maci64)
But the correct values for your system depend on which gcc/g++ you have and where they are installed. As you can see, I have the MacOS 10.6 Developer tools installed under /Develop. You will need an install of the Developer tools (XCode) - see
How to use/install gcc on Mac OS X 10.8 / Xcode 4.4
In more recent versions of the XCode tools, the path might look more like:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk
But compiling MEX code with more recent versions of XCode might cause other problems - I had issues with char16_t, see:
MEX compile error: unknown type name 'char16_t'

Matlab r2013a doesn't recognize any compiler in order to protect a model

I have a problem with my r2013a Matlab.
I want to protect a model using Simulink.ModelReference.protect('test') command. For this
I have to configure my compiler. I'm using the mex -setup command, and the xpcsetCC -setup command.
At first, Matlab says that is all ok with the compiler, but when i try to execute the Simulink.ModelReference.protect('model') command it shows an erro saying that there is no compiler avaiable.
Here are the sequences of commands:
PART 1 - 'mex -setup'
INPUT
mex -setup
OUTPUT
Welcome to mex -setup. This utility will help you set up
a default compiler. For a list of supported compilers, see
http://www.mathworks.com/support/compilers/R2013a/win64.html
Please choose your compiler for building MEX-files:
Would you like mex to locate installed compilers [y]/n?
INPUT
y
OUTPUT
Select a compiler:
[1] Intel C++ 12.0 (with Microsoft Software Development Kit (SDK) linker) in C:\Program Files (x86)\Intel\ComposerXE-2011\
[2] Intel C++ 12.0 (with Microsoft Visual C++ 2010 linker) in C:\Program Files (x86)\Intel\ComposerXE-2011
[3] Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files (x86)\Microsoft Visual Studio 10.0
[4] Microsoft Visual C++ 2010 in C:\Program Files (x86)\Microsoft Visual Studio 10.0
[0] None
Compiler:
INPUT
4
OUTPUT
Please verify your choices:
Compiler: Microsoft Visual C++ 2010
Location: C:\Program Files (x86)\Microsoft Visual Studio 10.0
Are these correct [y]/n?
INPUT
y
OUTPUT
***************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2010 require
that Microsoft Visual Studio 2010 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************
Trying to update options file: C:\Users\Guilherme\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2013a\bin\win64\mexopts\msvc100opts.bat
Done . . .
**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/help/matlab/matlab_external/upgrading-mex-files-to-use-64-bit-api.html
Building with the -largeArrayDims option enables the new API.
**************************************************************************
PART 2 - 'xpcsetCC -setup'
INPUT
xpcsetCC -setup
OUTPUT
Select your compiler for xPC Target.
[1] Microsoft Visual C++ Compilers 2010 Professional in C:\Program Files (x86)\Microsoft Visual Studio 10.0
[0] None
Compiler:
INPUT
1
OUTPUT
Verify your selection:
Compiler: Microsoft Visual C++ Compilers 2010 Professional
Location: C:\Program Files (x86)\Microsoft Visual Studio 10.0
Are these correct [y]/n?Y
Done...
Until now everthing is ok, but next there is an error:
Part 3 - Simulink.ModelReference.protect('test')
INPUT
Simulink.ModelReference.protect('test')
OUTPUT
### Model reference SIM target (test_msp.mexw64) for model test is out of date because test_msp.mexw64 does not exist.
### Updating model reference SIM target for model: test
Warning: The model 'test' does not have continuous states, hence Simulink is using the solver 'VariableStepDiscrete' instead of solver 'ode45'.
You can disable this diagnostic by explicitly specifying a discrete solver in the solver tab of the Configuration Parameters dialog, or by
setting the 'Automatic solver parameter selection' diagnostic to 'none' in the Diagnostics tab of the Configuration Parameters dialog
Warning: Using a default value of 0.2 for maximum step size. The simulation step size will be equal to or less than this value. You can disable
this diagnostic by setting 'Automatic solver parameter selection' diagnostic to 'none' in the Diagnostics page of the configuration parameters
dialog
### Build procedure for model: 'test' aborted due to an error.
Error using Creator.protect (line 287)
An installed compiler was not detected. Certain simulation modes, as well as host-based coder builds require that a compiler be installed. Please
install one of the supported compilers for this release as listed at:
http://www.mathworks.com/support/compilers/R2013a/win64.html
MATLAB must be restarted after the compiler is installed.
Error in C:\Program Files\MATLAB\R2013a\toolbox\simulink\simulink\+Simulink\+ModelReference\protect.p>protect (line 74)
[harnessHandle, neededVars] = protectedModelCreator.protect(varargin{:});
I've already tried all different choices of available compilers. I also tried to choose no for the fist question of mex -setup ("Would you like mex to locate installed compilers [y]/n?") and choose the compiler manually. None of this worked.

make error: invalid command line option

I'm trying to make http://iridia.ulb.ac.be/~manuel/hypervolume (version 2.0) on windows using the instructions they've given in their README which is to install MINGW and run "make mex", however I keep getting this error:
$ make mex
mex -D VARIANT=4 Hypervolume_MEX.c hv.c
mex.exe: Invalid command-line option
mex.exe: Data: unknown option
make: *** [mex] Error 1
instructions given:
Guillaume Jacquenot contributed a MEX interface for MATLAB
(Hypervolume_MEX.c). Use make mex to compile it.
Any help would be appreciated thank you
Within matlab change directories to the location of the hypervolume code, then run
mex -DVARIANT=4 Hypervolume_MEX.c hv.c avl.c
at the matlab command prompt. If your c compiler is set up correctly within matlab this should generate an executable named Hypervolume_MEX.xxx (dll in my case).
edit
I used the matlab compiler (Lcc C 2.4) on Matlab 7. No luck with Visual Studio 6 or Watcom 10.6 compilers (although I did not attempt to debug).

which configuration option is used by Mex to compile using matlab?

say, if choose mexopts.sh as the configuration files for mex,
then how does mex decide which option listed in the mexopts.sh is used for compiling?
for example, using 32bit matlab on 64bit mac os x:
mexopts.sh looks like:
,,maci
........
,,maci64
......
Then, maci or maci64 is used when compiling?
What commands or way can I do in order to compile 32bit lib instead of 64bit lib?
Further explanation of my process and the error message I got :
I am using mac os x 10.8 (64bit) with matlab R2010a (32bit) to produce a binary mex-file.
The Xcode is 4.6 version, I installed Command Line Tools on my machine. Then I downloaded the patch from matlab for 2011 and 2012 version anyway. (if I don't install the patch, I got a lot of link errors saying some header files are missing).
After I installed the patch ( I believe it changes my mexopts.sh file), when I run mex a.cpp, I got error message saying that /Applications/MATLAB_R2010a.app/bin/maci64 cannot be found. Of course, it cannot find the maci64 folder, it is 32bit, there is only maci folder.
So Anyone knows what I should do in order to make matlab look for maci folder instead of maci64 folder? Thanks a lot!
MATLAB does not support cross compilation of MEX files. So your 32-bit MATLAB installation should be producing 32-bit MEX files even though the OS is 64-bit.
Also, from the article I've linked
Further, beginning with R2010b, a 32-bit version of MATLAB is no longer produced for the Mac.
If you're running R2010b or later, your MATLAB is not 32-bit anyway.
To see what switches the MEX script is invoking the compiler with, use the -v option.
You can also use the file tool to check whether the generated binary is 32 or 64-bit.
As its been explained, MATLAB produces MEX files of the same bit-ness as itself, not that of the OS. This is true at least on Windows with recent MATLAB versions, where you can have either 32-bit or 64-bit MATLAB running on 64-bit Windows. Other platforms are moving towards 64-bit versions only.
Here is another way to get the configured mex switches:
>> cc = mex.getCompilerConfigurations
>> cc.Details
In my case I get:
>> cc = mex.getCompilerConfigurations
cc =
CompilerConfiguration with properties:
Name: 'Microsoft Visual C++ 2010'
Manufacturer: 'Microsoft'
Language: 'C++'
Version: '10.0'
Location: 'C:\Program Files\Microsoft Visual Studio 10.0'
Details: [1x1 mex.CompilerConfigurationDetails]
LinkerName: 'Microsoft Visual C++ 2010'
LinkerVersion: '10.0'
>> cc.Details
ans =
CompilerConfigurationDetails with properties:
CompilerExecutable: 'cl'
CompilerFlags: [1x115 char]
OptimizationFlags: '/O2 /Oy- /DNDEBUG'
DebugFlags: '/Z7'
LinkerExecutable: 'link'
LinkerFlags: [1x327 char]
LinkerOptimizationFlags: ''
LinkerDebugFlags: '/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"'
To answer my own question, just for those who may be interested in it,
I checked the contents of mexopts.sh and modified the part for maci (specifically set ARCH=i386) , then compile. The error message is gone.