How can I tell MMA where to find c header files for compilation? CreateLibrary is returning C1083 can't find stddef.h. Details follow...

Windows 10 - 1709 using Visual Studio 2015 (Community Edition, update 3), having modified VisualStudioCompiler.m to reference VS 2015)

by modding Line 280 to

$VisualStudioVersions = {"2015", "2013", "2012", "2010", "2008", "2005"}

and adding

installPath["2015"] := installPathFromEnvironment["VS140COMNTOOLS"]

Compiling generally works; the problem is with creating a library. Specifically the example in the documentation at CCompilerDriver/ref/CreateLibrary.



The documentation example continues with

add1src = "
 #include \"WolframLibrary.h\"

When the final library creation input

add1lib = CreateLibrary[add1src, "add1"]

is executed the result is

"Compile error: "C:\ Program Files \ Wolfram Research \ \ Mathematica \ 11.0\ SystemFiles \ IncludeFiles \ C \ \ WolframLibrary.h(24): fatal error C1083: Cannot open include file: \ 'stddef.h': No such file or directory "

Now. the opening lines of WolframLibrary.h are:


#include "setjmp.h"

#define WolframLibraryVersion 3


#include <stddef.h>
#include "dllexport.h"
#include "extern.h"

So it is < stddef.h > which can't be found.

Now, in Visual Studio unders Windows 10, sttdef.h is to be found in e.g.

C:\Program Files (x86)\Windows Kits\10\Include\10.0.16299.0\km\crt

(there are several, other subfolders of Include are 10.0. {14393, 10586,102140, 10150})

My questions are:

1/ Where does MMA look for e.g. stddef.h, i.e. where is the path specified

2/ How can I tell MMA to look in a location I specify, such as above

Many thanks!

Extra Information per Szabolcs' suggestion

After "ShellCommandFunction" -> Print, "ShellOutputFunction" -> Print

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64

cl.exe /LD /O2 /MT /I "C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\IncludeFiles\C" /I "C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\include" "C:\Users\Julian\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-lotan-8708-15120-1\add1.c" /link /implib:"C:\Users\Julian\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-lotan-8708-15120-1\add1.lib" /LIBPATH:"C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\lib" /LIBPATH:"C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\Libraries\Windows-x86-64" "ml64i4m.lib" /out:"C:\Users\Julian\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-lotan-8708-15120-1\add1.dll"

C:\Users\Julian\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-lotan-8708-15120-1>call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64 Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved.

add1.c C:\Program Files\Wolfram Research\Mathematica\11.0\SystemFiles\IncludeFiles\C\WolframLibrary.h(24): fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory

  • $\begingroup$ When something like this happens, always look at the output from "ShellCommandFunction" -> Print, "ShellOutputFunction" -> Print (options to CreateLibrary) and include it in the question. $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 13:38
  • $\begingroup$ That said, the most likely reason is that you did not install the necessary headers with Visual Studio. I rarely use Windows, so I cannot give any specific details, but as I remember there are several components one can choose while installing VS. The headers might be a separate one. See e.g. here: social.msdn.microsoft.com/Forums/vstudio/en-US/… $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 13:40
  • $\begingroup$ Personally, I don't install VS anymore just for use with Mathematica. I only install the command line tools. You can install the 2015 (not 2017!!) build tools and get rid of the VS GUI for good if you don't need it for anything else. microsoft.com/en-us/download/details.aspx?id=48159 The 2017 build tools only work with recent versions of Mma (11.2??) and the simple patch you show about won't be sufficient to use them. I can confirm that Mathematica works fine with the 2015 build tools. $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 13:42
  • $\begingroup$ @Szabolcs I did actually do it your way with the build tools first, but now I need other VS capabilities. I'm afraid I don't understand your idea that I might not have installed the necessary headers since I provided a list of paths to stddef.h... did you mean some other headers? If so, which, why etc.? I think (but can't prove now) that because I wasn't planning to build apps with VS & did not initially install the Universal Windows App Development Tools (where they now live it seems) they were NOT included before - but they definitely exist now. $\endgroup$ Apr 1, 2018 at 13:49
  • $\begingroup$ I mean that when you install VS, the installer presents you with a number of checkboxes. Only checked components will be installed. I suspect that a relevant component may not have been checked. This is only a guess though. $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 14:14

1 Answer 1


I doubt this is related to Mathematica. Can cl.exe compile any program containing #include <stddef.h> from a VS2015 command prompt?

These headers would be provided by selecting the "Universal CRT SDK" component when installing Visual Studio, but in this case also the OS version might be relevant.

From https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk

Note: Windows 10 development targeting Windows 10 Creators Update (or later) requires Visual Studio 2017. This SDK will not be discovered by previous versions of Visual Studio.

For the specific questions, (1) Mathematica does nothing special, the issue is whether the compiler itself can find these and (2) additional include paths can be specified via the "IncludeDirectories" option, but that should not be necessary in view of (1).

  • $\begingroup$ That (other than MS putting the headers in a new place) makes sense & thanks for the link/quote. I'm adding a VS2017 install and will report how that goes $\endgroup$ Apr 1, 2018 at 15:33
  • $\begingroup$ @JulianMoore If you have an older version of Mathematica that required the patch you mentioned, it won't be able to use VS2017. $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 15:55
  • $\begingroup$ @szabolcs I have 11.0.1... dare I hope that can use vs 2017? I was planning on making similar edits once the VS15 environment variable had been set up (which it isn't by default, but easy to do manually) $\endgroup$ Apr 1, 2018 at 17:36
  • $\begingroup$ @Julian The same edit won't work for VS2017. At least M11.2 is needed ... mathematica.stackexchange.com/q/140071/12 $\endgroup$
    – Szabolcs
    Apr 1, 2018 at 17:49
  • 1
    $\begingroup$ @Julian Not released independently to my knowledge, though it may be worth asking support for it. Also I think it should be possible to use VS2015, just not with the latest SDK. Maybe reinstallation could help. $\endgroup$
    – ilian
    Apr 3, 2018 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.