How to Install the MinGW-w64 Compiler in Matlab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone and welcome to another video today I'd like to talk about how to install the mingw W 64 compiler in MATLAB now you might look at that title and say wow this seems like a really esoteric topic why would I ever want to do this here well I'm glad you asked that question why don't we jump over to Simulink and take a look at why you might actually need or want the mingw w 64 compiler for matlab alright so one guy here is a Simulink model that I'm actually using to interface and control and Arduino here now the interesting part about this model here is it actually contains a block which is an S function here so you might recall here that an s function is effectively a simulant wrapper to C C++ or Fortran code so therefore in order to execute this model here MATLAB needs to compile this C code here into something that's executable here so in order to do that it's going to need a C compiler so right now since I don't have a C compiler on this machine here if I go ahead and try to hit run it's gonna try to compile but then it's going to fail here and actually if you take a look here it actually gives a fairly helpful error message stating exactly why I've failed and luckily a couple of links on how to resolve this the resolution is basically to link or install a C compiler onto your machine here so in order to do that this is actually fairly reasonable one potential option here is you could come back to MATLAB now if you had a C compiler on your machine but MATLAB simply wasn't linked up to that right now you could type in here and same X - set up and hit enter and it would give you an option to link to any of these supported compilers on your machine you might want to note here that not all compilers are supported in this fashion for example on my machine I have Microsoft Visual Studio 2017 which is a perfectly valid C compiler right if you look here let me see visual studio here we go I got Visual Studio 2017 on this machine but it's actually not gonna work for this workflow here so MATLAB is not gonna allow me to select or link to this compiler so instead need to use method two which is the suggested procedure of installing the mingw w 64 compiler here so why don't we go ahead and do that now so to get that all I need to do here is come here to home add-ons and let's click on get add-ons and when the add-on Explorer comes up what we're gonna do here is we are you're just gonna simply search for mingw and hopefully that will show up so I'll come here in the search bar and say mingw and click on search and here it is here's the Matloff support for the min gww 64 c compiler so this is what we're looking for so let's go ahead and click on it and now unfortunately if you look here this might ring a bell for those of you who watched our video talking about getting the simulate support package for arduino hardware set up and running you who may notice that we ran into this issue earlier here where basically I am running a older version of MATLAB I'm running our 2016 be here and there are some issues associated with that in terms of how to download third-party software here so there is a workaround that I am gonna have to go through here but hopefully you are not gonna have to do that if you have an earlier newer version of MATLAB namely our 2017 B or later you shouldn't be affected so if you have a newer version of MATLAB feel free to just skip ahead a few minutes here in the video while I go ahead and implement this workaround alright so let's just go ahead and click on the report here and it's gonna take us to a website here I'll include the URL in the description of this video here but basically this describes what the problem is and luckily they have a fairly reasonable workaround for this so I'll let you read through this at your own leisure if you're interested but what this basically amounts to is scrolling down all the way to the bottom here and finding a zip file which contains a few files that we are gonna have to overwrite in our MATLAB installation so I'm gonna find the one that's appropriate for me so here it's this one it sure looks like this is affecting MATLAB our 2013 B through 2017 a for Windows so this is what I'm looking for so I'm gonna go ahead and download that file here I'll go ahead and accept the limited license here and now let's go ahead and look at that folder or look at that file and we see it's just a zip file and if I go ahead and extract all of these to this location I can go ahead and look inside here and we see that what this basically is is there's a single file here that we need to add to our MATLAB install directory here if you can actually even look at this it's it's it's very very simple it's all it's doing is is changing a communication protocol here so it's a very minor change here there's a few other files here in this bug report directory as well that will need to be added to our MATLAB path here so in order to do that why don't I first come back to MATLAB and let's figure out where is MATLAB installed so if I type in MATLAB root here's where this is its installed in see Program Files MATLAB R 2016 so I'm gonna go ahead and copy this here and let's come back to our Windows Explorer here and tell you what I'm gonna move this to one side like maybe move it over here and let's fire up another instance of Windows Explorer move it to the other side here and let's go take a look at that directory here make a note that this is in the Program Files directory so you may need to be logged in as a user who has administrator rights because what we're going to try to do now is if you look here there is a bin here in the new downloaded file that we're going to replace and there's a bin file here there's a bug report folder here there's a bug report folder over here so all we need to do is basically make replacements here to quote unquote upgrade our old version of MATLAB 2016 B so let's start with a bin so if we look over here this is the new version of the file called bin in W 64 there's one file so again I'll come over here in bin and I'll come in W 64 and actually there is no file in here called Java table so if I search for Java there's just one file called Java launcher DLL so actually that's great I don't need to make any backups here I can just simply go ahead and copy this full file and paste it in and again it looks like I need administrator rights so yep let's that's totally fine let's go ahead and paste that thing in and all right let's come back up to our MATLAB route and also over here we will come back up a few levels come here to the bug report let's go into bug report and we see that okay here is this file I don't see a corresponding file already so I'll go ahead and just simply go ahead and copy paste it into here again I need administrator rights now the license here is the same in both so math works actually recommends making a copy of the existing one which probably isn't a bad idea so I'll go ahead and copy that and I'll just paste this into some random location on my machine maybe I'll call this thing old just so I have it in case I need to go back so with that backed up I can go ahead and copy the new license and paste it into here alright so there we go so again I need administrator rights let's go ahead and say yes okay so theoretically that should be the implementation of the work around here so with that being said why don't we go ahead and restart MATLAB so I'll go ahead and close the add-on Explorer I'll close MATLAB here which is going to kill Simulink while we're at it here and then let's go ahead and restart MATLAB and once this comes up we'll go ahead and start installing the package here so I'm gonna pause the video for a second oh actually never mind that came up much quicker than I thought here so let's come here to add-ons get add-ons and I don't once again once the add-on Explorer pops up here let's go and maximize they get ourselves a little bit more real estate here let's go ahead and again search for the mingw and click on this again get the same page and again now we have addressed this issue here so we should be able to go ahead and hopefully be able to come here and install so let's go ahead and install and this may take a little while here so we'll go ahead and pause the video and come back if anything interesting happens so I'm asked to accept this I'll go ahead and hit accept and again it looks like it's more waiting so again let's go ahead and pause the video okay and here we are with another notification third party software we can view the license if we want but I don't I'm just gonna go ahead and hit next and here we go we're off to the races to start downloading and installing the packages so again let's go ahead and hit pause on the video and come back if anything interesting happens and we're back and it looks like the installation was complete um in the interest of full disclosure here during the installation process I actually had to let setup.exe make changes to my hard drive as well as authorized a quote unquote MathWorks privileged operation I didn't bother turning on the screen recording for that because it was just clicking yes twice here but that got us at this point so let's go ahead and hit finish at this point and we should have this thing hopefully installed so again let's close the add on manager and for completeness I sure like to just restart now laughs so let's go ahead and close MATLAB I'll close the bug report don't need that any longer and let's reboot MATLAB get him started again here and verify that this works so what we're gonna do here is first let's just make sure that the min gww 64 compiler has been added here and is recognized so I'm gonna come here to my command window and just now type in Mex setup and here we are this looks very promising it says that math is now configured to use that compiler that we just set up so that's perfect why don't I now go ahead and open up that Simulink model that threw the error earlier so I'll just run this script which I use to initialize variables and to open the model in question here and we'll give se me like a second or two to start up and what we can see here is here's my Simulink model again if you recall this is the one that when we try to execute it it gave us a bit of an issue due to the s function and the lack of a compiler but now that we have this installed let's go ahead and try to run this now so I'll just go ahead and hit play here or hit run and you're seeing it's building it's compiling we can actually click on this view Diagnostics button here and aha look at that building with the me and GW C compiler and it looks like it was completed successfully so that was good although it's it's we're not done yet right it still says it's building so maybe we should give us a few more seconds but where we declare victory here so we see MATLAB is still running through a couple of processes here it's probably um potentially still compiling I'm actually not 100% sure any longer what it's still working on here but for those of you who have ever worked with Arduino or the seemingly Support Package with Arduino Hardware or running models externally I think you realize that this build process sometimes can take a little longer than you'd like here which is unfortunately what we're doing here but aha Hey look at that that looked good look at this and here we are and that looks like a win here because look at this we are now running that this model here successfully on an Arduino externally here so that being said I think this showed how to solve the problem of getting s functions running in your Simulink model and basically again we solve that problem by installing the min gww 64 compiler here on MATLAB so I hope you enjoyed this video I hope it was helpful if you did please subscribe to the channel we will have new videos talking about Mallove's Simulink and arduino in the near future so thank you very much and I hope to catch you at the next video bye
Info
Channel: Christopher Lum
Views: 42,564
Rating: undefined out of 5
Keywords: Matlab, Matlab MinGW-w64 compiler, s-function, Simulink
Id: 12XRTUqG94Y
Channel Id: undefined
Length: 12min 18sec (738 seconds)
Published: Sun Oct 07 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.