Simulink Matlab Function Block Error

3 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
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
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.

Community Treasure Hunt

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

Start Hunting!