clang on windows (installed via scoop) is unable to find headers (a copy from stackoverflow I wrote myself but can still be helpful)

in #programminglast year

Trying to compile a simple hello world example using clang on windows fails and i dont know why since the command below displays locations that contain possible headers.

C:\Users\peter\Downloads>clang-cl -v hello.c
clang version 3.9.1 (branches/release_39)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Users\peter\scoop\apps\llvm\current\bin
"C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\clang-cl.exe" -cc1 -triple x86_64-pc-windows-msvc19.0.24215 -emit-obj -mrelax-all mincremental-linker-compatible -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -D_MT -flto-visibility-public-std --dependent-lib=libcmt --dependent-lib=oldnames -stack-protector 2 -fms-volatile -fdiagnostics-format msvc -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\..\\lib\\clang\\3.9.1" -internal-isystem "C:\\Users\\peter\\scoop\\apps\\llvm\\current\\bin\\..\\lib\\clang\\3.9.1\\include" -internal-isystem "F:\\visualstudio2015\\VC\\include" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -internal-isystem "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.1A\\" -fdebug-compilation-dir "C:\\Users\\peter\\Downloads" -ferror-limit 19 -fmessage-length 120 -fms-extensions -fms-compatibility -fms-compatibility-version=19.0.24215 -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\peter\\AppData\\Local\\Temp\\hello-8512ad.obj" -x c hello.c
clang -cc1 version 3.9.1 based upon LLVM 3.9.1 default target x86_64-pc-windows-msvc
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
ignoring duplicate directory "C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A
End of search list.
hello.c(3,10):  fatal error: 'stdio.h' file not found
#include <stdio.h>
1 error generated.


As the command shows i installed llvm from scoop eg and tryed to compile code by simply calling clang.exe.

i was looking at

and i can confirm that i dont have an environment variable named INCLUDE in either my user environment variables or my system environment variables

running clang from inside the "VS2015 x64 Native Tools Command Prompt" shortcut seems to work (based upon just running "clang hello.c" from the downloads directory) however how do i apply whatever changes that shortcut makes to a currently running cmd prompt?

The reason i'm not using cygwin/msys/mingw is because i believe them to be too heavy both diskspace-wise and complexity wise.


well to answer that question those shortcuts call

"<location of visual studio install path>\vcvarsall.bat" <platform you want to build for>

or to present the whole command

%comspec% /k ""F:\visualstudio2015\VC\vcvarsall.bat"" amd64

so if you want to apply the contents of the shortcut to a currently running command environment execute this in the command prompt.

"F:\visualstudio2015\VC\vcvarsall.bat" amd64

so how does this apply to clang?

well the clang version you installed does not have the headers to compile a simple hello world example on windows. This is because there are many toolchains that can be used on windows and the toolchains don't have a standard location of where they install their headers. so clang needs a little help from them to find the headers.

this is where the vcvarsall.bat file comes in. it supplies the needed information for clang to use the installed msvc version headers and libraries.


Congratulations @jfmherokiller! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s) :

You published more than 450 posts. Your next target is to reach 500 posts.

You can view your badges on your board And compare to others on the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP

Do not miss the last post from @hivebuzz:

The Hive community is in mourning. Farewell @lizziesworld!
Support the HiveBuzz project. Vote for our proposal!