MATLAB Answers

Why is the build process failing for a shipped model in Simulink or for a model run in Accelerator mode?

344 views (last 30 days)
When I try to build a built-in demo, I get an error message stating that the build has failed. I have a supported compiler installed and properly set up.
The error message will look similar to the following:
NMAKE : fatal error U1073: don't know how to make 'C:\Program'
The make command returned an error of 2
'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command,
operable program or batch file.
A similar error may occur in the build log for models that are run in Accelerator mode.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Jun 2018
Edited: MathWorks Support Team on 15 Jun 2018
The problem with the build process is due to the following lines in the "" makefile. The .mk file contains the following code:
MATLAB_ROOT = C:\Program Files\MATLAB\R2013a
ALT_MATLAB_ROOT = C:\Program Files\MATLAB\R2013a
MATLAB_BIN = C:\Program Files\MATLAB\R2013a\bin
ALT_MATLAB_BIN = C:\Program Files\MATLAB\R2013a\bin
Since the MATLAB_ROOT and ALT_MATLAB_ROOT variables have the same value, the makefile was using the MATLAB_ROOT value with spaces. The build process does not know how to handle files with spaces in the path. MATLAB normally populates ALT_MATLAB_ROOT with the short path name, usually "C:\PROGRA~1". However, on some Windows systems generation of short path names may be disabled. Also, if MATLAB was itself installed in a path with a space in it (such as C:\Program Files) in the R2015a SP1 update and later releases, the issue was fixed and would not occur.
The proper code should have been as below:
MATLAB_ROOT = C:\Program Files\MATLAB\R2013a
MATLAB_BIN = C:\Program Files\MATLAB\R2013a\bin
There are a few methods for resolving this issue.
  • SOLUTION 1 - Using Windows short names:
This is perhaps the easiest of the solutions. There is a setting in Windows registry that enables/disables the generation of short names for file paths. Please use the following steps to change this setting:
(NOTE: Due to Windows security settings on the Program Files folder, this method may not work. If you receive a message during step 4 that says "Error: Access is denied.", please use one of the other solutions.)
1. Go to Windows Start menu and search for "regedit.exe". A new window will open.
2. Navigate to the following location:
3. Change the value of "NtfsDisable8dot3NameCreation" to 0.
Changing the value to 0 will enable the usage of short names in Windows paths. More information about this could be found at Microsoft's website:
4. However, changing the value above will only set short names files and folders that are created after making the change. To set a short name for use the "fsutil" function in Windows command prompt. The syntax to set the short name is as follows:
> fsutil file setshortname <FileName> <ShortName>
For the example of "C:\Program Files" the user would issue the following command to set the short name for "Program Files" to "PROGRA~1".
> fsutil file setshortname "C:\Program Files" PROGRA~1
The directory needs to be in quotations because it has spaces.
5. To check that the short name was set correctly use the "dir" command with "/x" option to show short names.
> dir C:\ /x
More information for "fsutil" can be found here:
  • SOLUTION 2 - Create a symbolic link to the MATLAB installation folder:
1. Open a Windows Command Prompt. And go to the C: directory.
2. Create the symbolic link to the location that your MATLAB versions are installed. The syntax is as follows:
> mklink /d <Link> <Target>
For example, a typical MATLAB installation folder is C:\Program Files\MATLAB. To make a link to that folder called MyMatlab use the following command:
> mklink /d C:MyMatlab "C:\Program Files\MATLAB"
If you open the new MyMatlab folder, you should see the folders for each version of MATLAB that are installed.
3. Create a new shortcut for MATLAB. This can go on your desktop or wherever you would like.
4. Right click on the shortcut and open Properties.
5. Go to the 'Shortcut' tab. In the 'Target:' option there will be a path to the executable that is used to launch MATLAB from this shortcut. Modify this path to use the newly created symbolic link. For the example above the, it should read
6. Launch MATLAB from this shortcut. Verify the location by typing "matlabroot" without quotations in Command Window, this should have no spaces in it now.
7. If you have multiple versions of MATLAB, repeat steps 3-6 for each version so that they will be launched from a location with no spaces in the path.
This solution will work for the newly created shortcuts. If you launch MATLAB from a different location it will not use the symbolic link and there will be the same issue with spaces in the path.
  • SOLUTION 3 - Change the MATLAB Installation Folder:
The reason we use short path is to avoid white spaces in the paths. By reinstalling MATLAB at a location without any spaces in the paths, you can workaround the build issue. However, this will require you to download and reinstall MATLAB.
For example, MATLAB can be installed at a path as below
Much like Solution 2, this solution will require you to reinstall MATLAB for all versions that you use.
  • SOLUTION 4 - Modify the template makefile
Another way around this issue is to encase the file names in double quotes. This will cause the build process to treat the file names enclosed in double quotes literally which will cause the build to succeed.
To do this, open the template makefile that you are using for code generation. Make a copy of this file and rename it. Inside this file, wherever "$(MATLAB_ROOT)" is used as part of a path, put a double quote before the "$" sign and after the last character in the path. For example, if the original line in the TMF was:
{$(MATLAB_ROOT)\toolbox\rtw\targets\xpc\target\build\xpcblocks}.c.obj :
The line would be replaced with:
{"$(MATLAB_ROOT)\toolbox\rtw_targets\xpc\target\build\xpcblocks"}.c.obj :
In "Configuration Parameters" -> "Code Generation" make sure that the "Template makefile" option points to the modified TMF, or else the changes will not be reflected in the generated code.
This method will need to be repeated for each template makefiles that is used.
A useful documentation page for MATLAB R2017a discussing the methods of enabling build processes for folder name with spaces can be found at the following link:
The limitations mentioned in the section 'Build Process Folder Support on Windows' are addressed in the methods mentioned above.


Show 4 older comments
Toby on 19 Jun 2017
Thanks for this detailed answer.
FYI, I've encountered this error* when running two concurrent sessions of 2016a. After encountering the error message, I closed the second session and re-ran the program in the first session, and the error did not appear again.
It may be worth noting that I have dashes in my working directory name. (i.e. "HWEC-Sim\HWEC-Sim\HW14\Results").
I hope that's helpful to somebody.
*"The make command returned an error of 2 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command, operable program or batch file."
Alan Bindemann
Alan Bindemann on 11 Oct 2017
The provided work-arounds listed here are not helpful to us and we share Mr. Soppelsa's frustration.
Solution 2 does not work for us under r2016b. (It did work under r2013b). Under r2016b matlabroot still returns "Program Files" even when started from the shortcut "ProgramFiles".
Solution 4 is also problematic. As pointed out in a previous comment, it is difficult to determine which template makefiles are being invoked, and editing them requires admin permissions on our machines.
Solution 3 is also not useful since the default installation directory for MATLAB is "Program Files" and asking our customers to reinstall MATLAB in a folder without spaces is not very practical. (For that matter, asking them to create and run MATLAB from custom symbolic links, or adding custom .tmf files to their installation is also problematic).
Solution 1 also doesn't work since our local security policy doesn't allow it.

Sign in to comment.

More Answers (4)

praveen mirajkar
praveen mirajkar on 4 Sep 2017
Hello all I'm getting below error
C:/ProgramData/MATLAB/SupportPackages/R2017a/toolbox/target/supportpackages/armcortexmbase/cmsis_rtos_rtx/src/mw_signal.c gmake: * No rule to make target `C:/ProgramData/MATLAB/SupportPackages/R2017a/toolbox/target/supportpackages/freedomk64f/src/ksdk_armgcc_lib/bm/libksdk_platform.a', needed by `../untitled.elf'. Stop. G:\Program Files\MATLAB\R2017a\untitled_ert_rtw>echo The make command returned an error of 2 The make command returned an error of 2 G:\Program Files\MATLAB\R2017a\untitled_ert_rtw>An_error_occurred_during_the_call_to_make 'An_error_occurred_during_the_call_to_make' is not recognized as an internal or external command, operable program or batch file.
I've tried all solutions still couldn't fix the problem , can anybody help??

KHALED on 7 Apr 2016
I'm using both Matlab 2015b and Matlab 2012b. I tried the second solution but it works only with Matlab 2012B. I don't know how to fix it with Matlab 2015b. Is there any other solution?

Salai Selvam V
Salai Selvam V on 20 Sep 2016
Dear friends, I appreciate the Mathworks Support Team for their effort in answering the queries. But to the best of my knowledge & experience, the answer seems to be little beyond the actual scenario. I faced the same problem with the same error messages but I DID correct it very simply not by any method mentioned here.
I had stored my files (the m file & wrapper c file) in a folder, namely:
THIS IS the problem: The folder names: "MATLAB&C" and "MATLAB2C" and TutorialToMATLAB2C".
I changed the folder names as:
This sorted out the problem.
My files:
1) The m file: coderand.m
function r = coderand() %#codegen
% The directive %#codegen indicates that the function
% is intended for code generation
r = rand();
2) The C wrapper file: main.c
** main.c
#include <stdio.h>
#include <stdlib.h>
#include "coderand.h"
#include "coderand_initialize.h"
#include "coderand_terminate.h"
int main()
printf("coderand=%g\n", coderand());
return 0;
3) The m script file: cccoderand.m
cfg = coder.config('exe');
cfg.CustomSource = 'main.c';
cfg.CustomInclude = 'D:\Research\MATLABAndC\MATLABToC\CODEGEN\TutorialToMATLABToC\CODERAND';
codegen -config cfg coderand;
That’s all friends. Thanks.


Sign in to comment.