Why is the "codegen" command failing with the error message “ninja: build stopped”?

I am attempting to generate a MEX file from MATLAB code using MATLAB Coder. 
Every time I execute the "codegen" command to build a MEX file, I get a long list of OBJ files that failed and an error message from ninja that the build stopped. For example, see the following error message snippet:
FAILED: build/win64/c_mexapi_version.obj
 
cl /c /Zp8 /GR /W3 /EHs /nologo /MD /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /DMATLAB_MEX_FILE /O2 /Oy- /DNDEBUG /fp:strict /I "." /I "D:\matlabTestLib" /I ".\interface" /I "C:\Program Files\MATLAB\R2020b\extern\include" /I "." -DMODEL=MTL_mex "C:\Program Files\MATLAB\R2020b\extern\version\c_mexapi_version.c" /Fobuild\win64\c_mexapi_version.obj
 
CreateProcess failed: The system cannot find the file specified.
ninja: build stopped: subcommand failed.
 
 
------------------------------------------------------------------------
??? Build error: C compiler produced errors. See the Build Log for further details.
More information
Code generation failed: View Error Report
Error using codegen
Why do I get this error message, and how can I generate code without this error?

 Accepted Answer

To resolve the above error, run the following command:
mex -setup
 and choose a new value for the desired compiler. Then, repeat this for
mex -setup C++
If the above steps do not work, it may mean that the cause of the issue is that the compiler was updated without executing "mex -setup". A possible workaround for this is to clear the existing XML files that specify which compiler the "mex" process will use, using the following steps: 
1.  At the MATLAB command line, execute:
>>cd(prefdir)
2. Delete the files "mex_C_win64.xml" and "mex_C++_win64.xml" in the MATLAB current directory.
3. Execute the "mex -setup" commands at the MATLAB command line again.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Release

R2022b

Community Treasure Hunt

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

Start Hunting!