Simulink Matlab Function Block Error

2 views (last 30 days)
duong phan
duong phan on 16 Oct 2020
Commented: Walter Roberson on 16 Oct 2020
Hi guys, I buil simple matlab function but it's not working. I don't know how to fix this problem. I used matlab R2012a
Please help me.
"Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.
Use 'mex -setup' to select a supported C-compiler."
  2 Comments
Ameer Hamza
Ameer Hamza on 16 Oct 2020
Which release of MATLAB are you using? Which OS?
duong phan
duong phan on 16 Oct 2020
I used matlab R2012a for Windows. what should I do now, Sir?

Sign in to comment.

Answers (2)

Sudhakar Shinde
Sudhakar Shinde on 16 Oct 2020
Edited: Sudhakar Shinde on 16 Oct 2020
To run mex function you need c-compiler. simply open command window and type:
mex -setup
If c compiler is available this command will list down available compiler. Then you can choose c-compiler.
If no any compiler is available on your system, you need to install it.
Check below link for supported compilers for MATLAB R2012.

Walter Roberson
Walter Roberson on 16 Oct 2020
If you are using 32 bit MATLAB and want to create 32 bit executables, then you can use the lcc32 compiler that is provided with that release. Just use
mex -setup
and have it select lcc .
However, normally it would already have selected lcc if you were using 32 bit MATLAB, so more likely is that you are using 64 bit MATLAB. For 64 bit MATLAB you should install Microsoft Windows SDK 7.1
Note: if you are using Windows 10, then it is difficult to install SDK 7.1 . On the other hand, MATLAB R2012a was never supported on Windows 10 -- only up to Windows 8 (and not Windows 8.1) . Installing SDK 7.1 on Windows 8 is a little bit of a nuisance but not too hard.
  3 Comments
Sudhakar Shinde
Sudhakar Shinde on 16 Oct 2020
Here is the steps to install windows SDK 7.1:
SDK 7.1 Installation step in window 10
Windows 10 already comes with .NET framework by default, following steps need to be followed to properly install the Windows 7.1 SDK.
  1. If installed, uninstall all versions of windows Framework.
  2. If present, remove all the Redistributable packages (both x86 and x64) prior to 2010.
  3. Install Microsoft SDK 7.1 from below link.
  4. http://www.microsoft.com/en-us/download/details.aspx?id=8279
  5. Note: SDK will not install Visual C++ compiler which we need to install from next step.
  6. Install Microsoft Visual C++ 2010 compiler package from following path
  7. https://www.microsoft.com/en-us/download/details.aspx?id=4422
  8. Restart the machine
  9. Open Matlab and type in the following command in the prompt:
>> mex –setup
10. If the SDK was installed successfully, Matlab will produce the choice to select it.
11. Select Microsoft windows SDK7.1
Walter Roberson
Walter Roberson on 16 Oct 2020
Historically it has been much more difficult than that. Sdk7.1 requires an older .NET version, and historically you could not install an older .NET without removing any newer versions, installing the old, and reinstalling the newer. That was possible for Windows 8. However Windows 10 did not permit .NET 4 to be uninstalled because it is core technology. That made it impossible to install the required older .NET for Sdk7.1.

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!