Why does my build fail with "fatal error C1083: Cannot open include file: 'xyz.h': No such file or directory", indicating that Visual Studio C++ compiler can't find C Standard Library headers?

119 Ansichten (letzte 30 Tage)
I encountered errors while running a build workflow in MATLAB/Simulink (MEX, Rapid Accelerator, Coder products, FMU Export, Simulink Compiler, etc) 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: 'limits.h': No such file or directory fatal error C1083: Cannot open include file: 'string.h': No such file or directory fatal error C1083: Cannot open include file: 'stdlib.h': No such file or directory fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
Everything works if I switch to the MinGW64 compiler.

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 16 Jul. 2025
Bearbeitet: MathWorks Support Team am 18 Jul. 2025

What This Issue Means

If Visual Studio C++ fails to locate C Standard Library headers such as string.h, stdlib.h, stddef.h, or limits.h, it typically indicates a problem with permissions, or with your Visual Studio and Windows SDK installation.

Quick Test: Start MATLAB as Administrator

Try running MATLAB as an administrator. If the build works this way, it likely means the Windows CMD tool doesn't have permission to access Visual Studio and Windows SDK header directories (see list below), which may be admin-owned. Work with your IT department to address this. See also the article linked from the "Further Troubleshooting" section below.

Alternative Workflow: MinGW Compiler

If Visual Studio C++ compiler is not required by your organization, your client, or your target workflow, consider using MinGW instead: How do I install MinGW for use in MATLAB?

Verify your Visual Studio Installation

If starting MATLAB as an admin didn't help, and MinGW is no option, let's first verify that your Visual Studio installation is complete:
1) Check Installed Workloads: Contact your IT department to verify your Visual Studio and Windows SDK installation. In most cases, the issue is due to an incomplete or missing installation of the "Desktop development with C++" workload. You can follow: How do I install Visual Studio for use with MATLAB/Simulink?
2) Confirm Header Paths and Files: Confirm that the C Standard Library headers are available in your Visual Studio installation. Typical paths are:
C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Tools\MSVC\14.41.34120\include C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Tools\MSVC\14.41.34120\ATLMFC\include C:\Program Files\Microsoft Visual Studio\2022\<edition>\VC\Auxiliary\VS\include C:\Program Files (x86)\Microsoft Visual Studio\2019\<edition>\VC\Tools\MSVC\14.29.30133\include C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt
Note: The exact path varies depending on your version and edition of Visual Studio and Windows SDK. You can locate the correct path by navigating through your Visual Studio and Windows SDK installation directories.
3) Test with a Simple Program: Next, open Visual Studio IDE and compile a simple "Hello World" C program that includes and uses several standard headers to verify that your setup is functioning correctly. Follow this YouTube Tutorial and use the "helloworld.c" code attached to this Answer. The expected output is shown in "expected_output.png".
⚠️ If the build fails in the Visual Studio IDE, work with your IT department to address this before proceeding with the next section.

Verify the Workflow in MATLAB/Simulink

After confirming that builds work in the Visual Studio IDE, open MATLAB. First, reconfirm that you selected the correct Visual Studio C++ compiler version using:
>> mex -setup
Then run the following basic tests in MATLAB and Simulink:
T1: Test MATLAB MEX workflow: Build a C-MEX File as shown in: Getting Help When MEX Fails.
T2: Test Simulink Rapid Accelerator workflow: If your goal is to use the Visual Studio C++ compiler with Simulink workflows, open the 'vdp' example model:
>> vdp
Go to the SIMULATION tab and change the mode from 'Normal' to 'Rapid Accelerator'. Press Run. You should see no errors.
T3: Test Simulink Coder workflow: If your goal is to use the Visual Studio C++ compiler with Simulink Coder workflows, open Model Settings > Solver > Solver Selection > Type in the 'vdp' model and select "Fixed-step". Close the settings and press CTRL+B.

Further Troubleshooting

If the MEX build (T1) succeeds but the Simulink builds (T2 and T3) fail, or only work when MATLAB is run as an admin, this likely indicates a permissions issue related to the Windows CMD tool, or the general execution of batch files (.bat) on your system. For more details, see:

Weitere Antworten (0)

Kategorien

Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by