Is it possible to use MATLAB on macOS to build a mex file for running on linux (with the .mexa64 extension)? Suppose that I have an appropriate compiler such as GCC. How would I do this? I couldn't find any useful arguments in mex.
I understand building for a different platform would require a full toolchain, but I'm wondering if MATLAB has one already under the hood.
Related
I use MATLAB 2012a. I need to compile a mex file in my program. Everything works fine with Microsoft SDK 7.1 but I need a minor compiler in order to work my program in other computers. Suggested compilers on MathWorks website are compilers that need to be installed as packages. Is there any compilers that work stand-alone and don't need to be installed?
You can use MinGW, but it is not straightforward. See this Q&A. The accepted answer suggest to compile and link MEX files outside of MATLAB, which is fine, but it's simple to just create mexopts.bat to do this.
A good mexopts.bat for MING is hosted here. Pick a MINGW distribution from win-builds and set the paths in mexopts. Then you can use mex -setup with this file.
gnumex is a disaster, IMO.
I am a total noob when it comes to compiling MEX files for MATLAB. I am thoroughly confused by the different versions of things, compilers, MATLAB versions, etc.
I have MATLAB 2013a, 64-bit, on a Windows-7 machine. I would like to add a C/C++ compiler to it, so that I can compile MEX files. This page here does not list the GCC compiler as a possible use.
However, for many files on the matlab exchange, they use GCC>= 4.2 apparently, for compiling MEX files.
So I am confused... all I want to do is run a MEX file, and install a compiler... does GCC work? If so why isnt it listed on the MATLAB page? Where do I start?...
Thanks!
I am trying to compile a C++ function (found here). I downloaded the requisite packages, installed Microsoft Windows SDK 7.1, linked it to MATLAB using mex -setup, and then unzipped the function packages into my MATLAB path.
When I run the command:
mex -output Faddeeva_w -O Faddeeva_w_mex.cc Faddeeva.cc
I get the error message:
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: 'Faddeeva_w_mex.cc' not found.
But if I type which Faddeeva_w_mex.cc I get:
C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\Faddeeva_w_mex.cc
So MATLAB and the which command have no problems finding the file, but mex is lost. This is my very first attempt at compiling something with mex, so I'm really not sure where to start here. Does mex have a different path variable that I have to set?
I'm using MATLAB 2013a on a Windows 7 64bit machine with the version of SDK 7.1 that was linked from the MATLAB List of supported compilers.
Either cd into the directory containing the files (assuming they both in the same place), or specify full/relative path to the C++ files when invoking mex function
Try putting addpath('C:\Users\craigim\Documents\Code\Matlab\Faddeeva-MATLAB\'); in your m-file. The path that MATLAB uses seems to be internal and independent of whatever your OS is using.
Documentation on addpath here.
And a similar discussion here.
You may also have to set your PATH environment variable to the string returned by the command fullfile(matlabroot,'bin',computer('arch')) in MATLAB. Here are some instructions on setting environment variables for Windows and Mac or Linux
There is also a pretty good overview of building mex-files here although I get the impression that the basics are not going to answer your question.
I packaged the 7.13 MCR compiler with my files (via desploytool).
I have some questions with assuming the client installed the MCR.
1) If the client doesn't have MATLAB, but just the MCR. he will be able to run my application by the MCR?
2) how can the client make the MCR compiler to be the default?
I tried:
mbuild -setup
Please choose your compiler for building standalone MATLAB applications:
Would you like mbuild to locate installed compilers [y]/n? y
Select a compiler:
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010a\sys\lcc
[2] Microsoft Visual C++ 2008 SP1 in C:\Program Files\Microsoft Visual Studio 9.0
[0] None
Compiler:
but I didn't see the MCR. his location is something like: C:\Program Files\MATLAB\MATLAB Compiler Runtime\v713 but I don't know what is the exactly path. should I know it?
3) should I have to make a bat file which configures the MCR to be the default compiler?
The MCR is not a compiler.
MCR is an abbreviation for MATLAB Compiler Runtime. When you use deploytool or mcc (available with MATLAB Compiler or the MATLAB Builder products), it converts your MATLAB program into a standalone component (e.g. an executable or library). You then give your end user the component and the MCR, and the component runs against the MCR instead of MATLAB.
The answer to your question i) is yes, your users only need the MCR, not MATLAB. Your users should not need to interact with mbuild at all, (and if they don't have MATLAB anyway, they can't). mbuild is used by you when preparing to create the component, not by your users when running it.
I think you confuse things. MCR is MATLAB Compiler Runtime. It does not provide any compiler, it allows one to run MATLAB programs compiled and deployed with mcc.
So the answer to your first question: yes, your client needs only to install MCR to run the programs you compile for him using mcc.
The answer to the other questions: there is no compiler..
I have a set of facial features that i have obtained and would like to classify using SVM. I intend to use libsvm package and use MATLAB to carry out the training.I have already read up on SVM by watching the Stanford lecture. But I am not sure how to use libsvm to start.. Need some guidance...
In matlab you can link your matlab code with some programs implemented in c. This a called a mex-file.
However you need to compile them, to make it work.
You can read the readme file to know how to compile them:
Installation
On Unix systems, we recommend using GNU g++ as your compiler and type
'make' to build 'svmtrain.mexglx' and 'svmpredict.mexglx'. Note that
we assume your MATLAB is installed in '/usr/local/matlab', if not,
please change MATLABDIR in Makefile.
Example:
linux> make
To use Octave, type 'make octave':
Example: linux> make octave
On Windows systems, pre-built binary files are already in the
directory `..\windows', so no need to conduct installation. Now we
include both 32bit binary files and 64bit binary files, but in future
releases, we will provide binary files only for 64bit MATLAB on
Windows. If you have modified the sources and would like to re-build
the package, type 'mex -setup' in MATLAB to choose a compiler for mex
first. Then type 'make' to start the installation.
Example:
matlab> mex -setup
(ps: MATLAB will show the following messages to setup default compiler.)
Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler:
1 Microsoft Visual C/C++ version 7.1 in C:\Program Files\Microsoft Visual Studio
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C/C++ 7.1
Location: C:\Program Files\Microsoft Visual Studio
Are these correct?([y]/n): y
matlab> make
For list of supported/compatible compilers for MATLAB, please check
the following page:
http://www.mathworks.com/support/compilers/current_release/