I wrote an application (GUI) in Matlab and I want to distribute it as a console exe file, does the user need to install MCR?
Short answer: Yes
I stole a nice answer from Matlab Central:
When using the MATLAB Compiler to compile MATLAB code into a
standalone executable, you do need to install the MCR because the
generated code calls into these runtime libraries. Also, you can
package the MCR together with the executable and have it installed
automatically when the executable is run. If you are using deploytool,
you simply need to select "Add MCR" and "Embed the MCR in the package"
from the Package pane.
Note that MATLAB Coder is the other product that actually allows you
to generate truly standalone C/C++ code from MATLAB code (without any
need for additional libraries like the MCR). However, it supports only
a limited subset of the MATLAB language.
Related
My program performs some simple calculations, look-ups and outputs an answer. What is efficient way to use a Matlab GUI program like I have as a standalone desktop application, which does not require Matlab as a prerequisite?
In order to run any Matlab program on a machine that doesn't have Matlab installed you will need to instal the Matlab Compiler Runtime (MCR).
This is a pre-requisite as it contains the Matlab core functionality that is required by your application and it is royalty-free.
So these are the steps you need:
In your Matlab installation, use the Matlab Compiler to generate a standalone executable of your program.
In the machine you want to deploy your application, Install the same MCR version than the Matlab version you used to generate your program.
Run the program
If you want to run a MATLAB application as stand-alone... whether it be a GUI or a script, it's not required that MATLAB be installed on your computer. You can, in fact, distribute any MATLAB application that you develop to those who don't have MATLAB installed on their computers, but you need the MATLAB Runtime libraries installed before doing so.
On the developer's end, the use of the MATLAB Compiler is required to make your MATLAB application stand-alone. You need to be cautious in that certain MATLAB functions from certain toolboxes cannot be compiled with the MATLAB Compiler if they are used as part of your MATLAB code in order to create your stand-alone application. This link from MathWorks gives a very comprehensive list of what is compatible per toolbox: http://www.mathworks.com/products/compiler/supported/compiler_support.html
On the user's end, simply get them to install the MATLAB Runtime libraries. That can be found here: http://www.mathworks.com/products/compiler/mcr/
Once the developer uses the MATLAB Compiler to create their stand-alone application and once the user installs the MATLAB Runtime libraries, then you can run any stand-alone MATLAB application. Be advised that there is no way around installing the MATLAB Runtime libraries. You need these for any MATLAB application to run stand-alone.
I'm encountering a serious problem while trying to deploy a Matlab program as a stand-alone for Windows.
My end users are employees in some corporation and have only access to static computers. While they can download, unpack and execute stuff, they don't have installation privileges, so they're unable to install the Matlab Compiler Runtime (MCR). Unfortunately, they need MCR in order to run my deployed/compiled Matlab program. The deploytool offers me the option to "include MCR in the package", but it doesn't really do that. Instead, it packages the MCR installer, which is useless in my case as described above.
So how can I create a stand-alone application that runs on Windows out of the box, even without MCR installed and without installing it first? There has to be a way to compile this all the way down to binary...
You can't run Matlab code standalone without having MATLAB or the MATLAB Compiler Runtime installed. But it is legal to distribute the MCR to the customers to make them able to use your programs.
Alternatively you can use the MATLAB Coder to convert your code to C/C++, which is not completely issue-free, as just a subset of the Matlab language is supported.
Have a look at this question for the differences between MATLAB Coder and MATLAB Compiler.
Just ask IT to install the MCR, that only needs to happen once. After that the users should be able to execute your programs.
Note: There is a reason that the MCR needs to be installed, and can't just be executed. Therefore I don't expect there to be a 'trick' to avoid this.
Let say I wrote a program which has GUI. And I want to share with my friend who don't have MATLAB in his computer. Can I some how convert it to Java or other language? I tried using deploytool but it need the target computer install MCR in order to work.
Yes, you should use MATLAB Compiler (which deploytool is part of) to create a standalone executable from your GUI. The end-user does require the MCR (MATLAB Component Runtime) to run your compiled application, but you can freely distribute it if you have a license of MATLAB Compiler.
Note: last I looked, the application are OS-specific, i.e. if you use Windows to compile your application, you can only deploy in on a Windows platform.
I am trying to execute some example code from a MATLAB toolkit, 'oscmex'. This toolkit allows for communication using the OSC protocol over MATLAB. I presume this question is non-specific; it should apply to any toolkit that is set-up in the manner that this one is.
Reasons aside, I'm having some simple trouble getting the toolkit up and running. The toolkit comes with no documentation whatsoever; just a set of six DLL files (in one directory), and a set of four MATLAB '.m' example code files (in another directory). Every toolkit I've used in the past has either been a built-in kit or has had an intuitive (semi-automated) install procedure.
After downloading the toolkit, the first thing I tried was to simply run one of the '.M' example codes. This failed as the first line of the code contained the function osc(), which is not (currently) recognised by MATLAB.
So, I figured maybe I need to move the '.M' files into the same folder as the DLLs; perhaps MATLAB would see the functions inside the DLLs. No dice.
So, I realise that I have to somehow link MATLAB to the DLLs on startup. I tried adding the DLLs to a folder and adding an entry to that in the 'pathdef.m' file. This also failed.
I've read somewhere I can load a DLL file by using the loadlibrary() function. So, I tried doing this for the DLL files. This failed on the first file:
>> loadlibrary('osc_free_address.dll')
Error using loadlibrary>lFullPath (line 587)
Could not find file osc_free_address.h.
I'm starting to run out of options... How can I get this set of DLLs up and running?
Browsing this library's web page it would seems these DLLs are just old form of mex files.
Therefore, they should not be used in the context of shared library (e.g., using loadlibrary and calllib), but rather compiled directly to mex files.
To do so, I would suggest the following steps:
Make sure you have a working mex compiler configured for your Matlab.
In matlab, type:
>> mex -setup
this will guide you through the configuration process. I understand that you are working on a windows machine, I usually work with visual studio compiler - works best for me.
This library's README file suggests that OSC
requires liblo 0.22 or later. See http://plugin.org.uk/liblo/
Make sure you have this library and it is located in you LD_LIBRARY_PATH (see e.g., this question for details, or the mex docs).
Get the source code for OSC library from their repository.
Compile the sources in matlab using
>> mex -O -largeArrayDims osc_free_address.c
>> mex -O -largeArrayDims osc_free_server.c
and so on for all 7 c source files. After mex-ing the c files you'll have mex files that you can run from Matlab as if they were regular functions.
You may find it useful to use the library's make file, as suggested by Andrew Mao.
Good luck,
If you look at the build for that software, it is compiling mex files, not DLLs (shared libraries): http://sourceforge.net/p/oscmex/code/4/tree/trunk/src/osc_make.m.
I would try using the mex commands instead of the dll commands (perhaps the files are just misnamed.) Even better, I would compile the files yourself with mex using the build file in source.
Note that the instructions also say that you need liblo-0.22 in order to run the library, so make sure you have that accessible as well.
I took a look at your OSC Toolkit. It seems they have been compiled by MATLAB mex. But, it is not mentioned for which kind of architecture they have been built. You can type mexext at MATLAB command prompt to find the extension for your MATLAB mex files. Then, change the DLL extensions to the given extension. If the original mex is compatible with your matlab, the DLL can be easily accessed by MATLAB. Just make sure to add the folder to your MATLAB path.
Try changing the extension from .dll to .mexw32 (in win32), or .wexw64 (in win64). It's a long shot but it might work.
The Shared Libraries cannot be used directly. As you have mentioned, you need to load them into MATLAB using loadlibrary. According to the documentation, loadlibrary takes two arguments (at least). The first argument is the name of the file, and the second one is the header file which contains definition of functions and external variables. If you do not provide the header file, the MATLAB looks for the a file with the same name as the DLL. Having said that, you need to have access to the header file or at least if you know how the function looks like, you need to write a header for the DLL.
I have worked with the DLLs in MATLAB. The MATLAB is not very user-friendly as long as DLL is concerned. Especially, if the DLL is written in a language other than C (or C++) you will have trouble loading the function into MATLAB.
Besides, MATLAB can only support some specific DLLs. Based, on your version of MATLAB, you need to find out whether or not the shared library is supported by MATLAB. Have a look at Here
In a nutshell, it is not easy to load a DLL into MATLAB. You need to have some information from DLL.
I have developed code on a m-file script in Matlab that communicates with a Measurement Computing USB-DAQ module, and I'm quite happy with that. The problem is that I don't want to purchase another license for the computer which is running the code. I have looked into Matlab Compiler Runtime tools, and it claims that I can deploy my mcc built executables to be royalty-free. Does that mean I can install the MCRInstaller (copied from the computer in which the Matlab is installed) on the host computer running the final product?
Yes. You install the Matlab Compiler Runtime (MCR) on the host computer that will be running the executable produced by the Matlab compiler.
Yes, you can install MCR and using the Deployment Tool it's easy to create a software package with all the files you need inside.