Why is the build process failing with error code: "NMAKE: fatal error U1073: don't know how to make 'C:\Program'"?

221 views (last 30 days)
When I try to build a built-in model, I get an error message stating that the build has failed. I have a supported Microsoft C/C++ compiler (Windows SDK/Visual Studio) installed and properly set up.
The error message will look similar to the following:
ERROR: NMAKE : fatal error U1073: don't know how to make 'C:\Program'
Stop.
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, or when building the model for Simulink Coder, Embedded Coder, or Simulink Real-Time.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 1 Sep 2022
Edited: MathWorks Support Team on 1 Sep 2022
The problem with the build process is due to the following lines in the "model.mk" 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 is 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". This issue may occur:
(1) If the generation of short path names is disabled on your Windows system.
(2) If MATLAB was itself installed in a path with a space in it (such as C:\Program Files) for R2014b and earlier. In the R2015a SP1 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
ALT_MATLAB_ROOT = C:\PROGRA~1\MATLAB\R2013a
MATLAB_BIN = C:\Program Files\MATLAB\R2013a\bin
ALT_MATLAB_BIN = C:\PROGRA~1\MATLAB\R2013a\bin
There are a few methods for resolving this issue:

SOLUTION 1 - Enable 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:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisable8dot3NameCreation
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:https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-2000-server/cc959352(v=technet.10)
4. However, changing the value above will only set short names for 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:https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc788058(v=ws.11) 
 

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 where 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
C:\MyMatlab\R2013a\bin\matlab.exe
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 paths 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
C:\MATLAB_Install\MATLAB\R2013a
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 makefile that is used.
A useful documentation page for MATLAB R2017a discussing the methods of enabling build processes for folder names with spaces can be found at the following link: https://www.mathworks.com/help/rtw/ug/enable-build-process-for-folder-names-with-spaces.html
The limitations mentioned in the section 'Build Process Folder Support on Windows' are addressed in the methods mentioned above. 
  9 Comments
Raheleh Biglari
Raheleh Biglari on 5 Nov 2021
Edited: Raheleh Biglari on 5 Nov 2021
It also works for me. I wanted to export simulink model to standalone FMU. I moved the simulink file to C drive (Matlab installed drive). And it works!

Sign in to comment.

More Answers (4)

VAIBHAV
VAIBHAV on 11 Mar 2016
Edited: VAIBHAV on 11 Mar 2016
Thanks Dear, I selected SOLUTION 2,Its working fine. Thanks

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
KHALED on 7 Apr 2016
Hello,
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?
Thanks

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.
SCENARIO BEFORE CORRECTION:
I had stored my files (the m file & wrapper c file) in a folder, namely:
D:\Research\MATLAB&C\MATLAB2C\CODEGEN\TutorialToMATLAB2C\CODERAND
THIS IS the problem: The folder names: "MATLAB&C" and "MATLAB2C" and TutorialToMATLAB2C".
I changed the folder names as:
D:\Research\MATLABAndC\MATLABToC\CODEGEN\TutorialToMATLABToC\CODERAND
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()
{
coderand_initialize();
printf("coderand=%g\n", coderand());
coderand_terminate();
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.

Community Treasure Hunt

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

Start Hunting!