Why does my Simulink Coder build, Rapid Accelerator build or FMU Export fail with "fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory" when using Visual Studio C++ compiler, referencing C Standard Library headers?

6 views (last 30 days)
I encountered errors while running a Simulink Coder build, Rapid Accelerator build, or FMU Export using the Visual Studio C++ compiler on Windows. The errors were related to missing C Standard Library headers like "limits.h", "string.h", "stdlib.h", or "stddef.h":
fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory
The same build works with the MinGW64 compiler. I verified that my Visual Studio setup is correct by successfully compiling a "Hello World" C program and creating a MEX file from MATLAB.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 May 2025
Edited: MathWorks Support Team on 2 May 2025

What This Issue Means

If Visual Studio is correctly set up with C Standard Libraries, antivirus software might be blocking the execution of batch scripts from the Temp directory, causing C1083 fatal errors as shown above.
During the build process for coder and rapid accelerator targets, a temporary batch file with a mangled name (e.g., tpd2732ef7_a3ed_4c29_804e.bat) is created in the Temp directory (C:\Users\%username%\AppData\Local\Temp\). This file calls "vsvarsall.bat" to set up Visual Studio C++ command line tools. Antivirus programs may block batch files from AppData or Temp directories, which are commonly used by malware.
A copy of this batch file is available as a permanent file setup_msvc.bat in \slprj\<target>\<modelname>\.
 

Try This Workaround

To enable automated Visual Studio builds in a restrictive environment, change the Temp folder location to a safe directory. Run these commands in MATLAB:
setenv('TMP', <path to a safe location>) clear tempdir
Note that "setenv" changes the Temp directory for the current MATLAB session only and does not affect other applications or system-wide environment variables.
After changing the Temp directory, rerun the coder build, rapid accelerator mode, or FMU export to confirm the workaround. To automate the execution of the above commands, place them in a startup.m script and add it to your MATLAB path, such as the MATLAB userpath.
 

Further Troubleshooting

If the above solution doesn't work, it could be that antivirus software is still blocking MATLAB from executing batch files.
Go into the \slprj\<target>\<modelname>\ folder in MATLAB and execute the following command:
>> !setup_msvc.bat
You should see output similar to the following:
>> !setup_msvc.bat C:\work\slprj\raccel\myModel>set "VSCMD_START_DIR=C:\work\slprj\raccel\myModel" C:\work\slprj\raccel\myModel>CALL "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\VCVARSALL.BAT " amd64 ********************************************************************** ** Visual Studio 2022 Developer Command Prompt v17.10.4 ** Copyright (c) 2022 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64'
If this is not the case, it could be that the antivirus software is fully blocking MATLAB. Review the logs of your antivirus software to check if it has recently blocked the execution of a BAT file called "setup_msvc.bat". Ask your IT helpdesk for assistance with allowing MATLAB to execute batch scripts.
If you are unsure which antivirus is installed on your system, you can get a list of all antivirus software installed on your system by executing the following command in the Windows Command Prompt (CMD):
[~,antivirus]=system('WMIC /Node:localhost /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct Get displayName /Format:List')
See the following article for further troubleshooting, including testing calls to 'nmake':

More Answers (0)

Categories

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

Products


Release

No release entered yet.

Community Treasure Hunt

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

Start Hunting!