1

I am trying to see if you can distribute a MEX file without requiring the end user to install the C++ runtime libraries. When you use visual 2010 express to create MEXs, Matlab issues this warning :


Warning: Applications/components generated using Microsoft Visual C++
2010 require that the Microsoft Visual Studio 2010 run-time
libraries be available on the computer used for deployment.
To redistribute your applications/components, be sure that the
deployment machine has these run-time libraries.


Is there a compiler that doesn't require to install the run-time libraries on the end machine?

Amro
  • 123,847
  • 25
  • 243
  • 454

1 Answers1

2

Yes there is: MinGW(-w64) GCC. It only links to the OS library msvcrt.dll (when you link with the -static option), which requires no installation and is part of Windows.

To get Matlab to work with that, you'll need to jump through some hoops. Here is some information. Ignore the Cygwin stuff, and be sure to use a MinGW-w64 toolchain targetting x64 Windows from the link above. Note I haven't personally tested this, but this is your best bet. It's also unsupported by Mathworks, so you are on your own.

As an aside, what's the problem with installing the MSVC++2010 redistributable anyways? There's no effect on licensing, and running MEX code implies having Matlab installed. Installing one more little thing won't be that much trouble IMHO.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Thanks, I will look it up. It is a little surprising to me that you have to go with unsupported compilers to do that. It is not possible to have a -static option with visual C++ compiler? The reason for this is that my end users are end users. I don't expect them to perform anything to get my code to work. Most of them would not know what is visual C++ so they won't understand what it is that they are installing. – Jerome Lecoq Jul 14 '12 at 17:36
  • 1
    @JeromeLecoq well, there is a static option, now that you mention it, but I believe all code needs to be compiled with that option (see [msdn](http://msdn.microsoft.com/en-us/library/abx4dbyh%28v=vs.100%29.aspx)) and I'm not sure if MEX stuff is compatible with that out of the box. An alternative solution is using the same version of VS as the redistributable that Matlab installs for itself, but that might be unfeasible. – rubenvb Jul 14 '12 at 19:17
  • Thanks. I think Matlab does not install any version of VS for itself. You have to install the compiler if you wish to use the compiling mex function. They used to ship LCC with Matlab but they are running away from this on the 64 bits plateform. They mention that they will completely stop providing LCC in 2013. – Jerome Lecoq Jul 14 '12 at 20:13
  • 1
    @JeromeLecoq: MATLAB will install VC++ redistributables when it installs (I think both 2005 and 2008, but not 2010). I can see two `vcredist_*.exe` inside the `bin` directory of MATLAB – Amro Jul 15 '12 at 12:48
  • @Amro: I didn't know that. 2005 and 2008 redistribution package comes with a Matlab installation. But here comes the problem: I tried to use C++ 2008 express but Matlab (starting in 2009) is not compatible with that compiler. So you HAVE to use microsoft 2010 express (unless you buy the professional 2008 C++ for 500$) or the corresponding SDK 7 or 7.1. In others words, you are stucked to use a compiler that Matlab does not preinstall with the corresponding libraries. I would guess they preinstall 2005 and 2008 because some of their own libraries are done with these? – Jerome Lecoq Jul 15 '12 at 21:36
  • @JeromeLecoq: I haven't tried this, but perhaps you can copy (on the client machines of course) the VS10 runtime into the same folder as the MATLAB exe, no install needed. In my case (WinXP 32-bit VS2010 Pro) the DLLs can be found in `C:\Program Files\Microsoft Visual Studio 10.0\VC\redist\x86\Microsoft.VC100.CRT`... I still think that the cleaner solution would be to tell your end users to make sure that [VC++ 2010 Redistributable](http://www.microsoft.com/en-us/download/details.aspx?id=13523) are installed. – Amro Jul 15 '12 at 22:03
  • @Amro. It will be not a clean solution. I agree. Especially since my users are going to be in the hundreds on many different computers. Do you think one could create an installation package with both microsoft runtimes and the MCR bundled? – Jerome Lecoq Jul 15 '12 at 23:39
  • 1
    @JeromeLecoq: I dont know much about creating installers, but I think all you have to do is add `vcredist_*.exe` as a prerequisite to your setup project. When the end-user runs the `setup.exe` installer, it will automatically install the VC++ runtime if needed. Here are some [related](http://stackoverflow.com/questions/7237635/can-vs-2010-setup-include-mcr-as-prerequisite) [questions](http://stackoverflow.com/questions/6623183/including-a-runtime-vcredist-x86-exe-as-part-of-an-installer) that might help.. – Amro Jul 16 '12 at 00:47