Skip to content

Instantly share code, notes, and snippets.

@InNoHurryToCode
Last active April 28, 2024 15:10
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save InNoHurryToCode/955d63db0d79699fed63fe18eeebf17e to your computer and use it in GitHub Desktop.
Save InNoHurryToCode/955d63db0d79699fed63fe18eeebf17e to your computer and use it in GitHub Desktop.
How to install clang on windows using the visual studio build tools

Clang on Windows (VS 2017 build tools)

There are plenty of tutorials online on how to install clang on windows with visual studioIDE and MinGW. However, there are none on clang with visual studio build tools.

Requirements:

  • 64-bit Windows 7 SP1 or newer with the latest updates installed
  • 6 GB of free space on the partition where Windows is installed
  • internet connection (for installation only)

1. Install VS 2017 build tools

%VS2017BuildToolsDir% = installation directory of VS 2017 build tools

  1. download and run the microsoft visual studio build tools
  2. select and install the following individual component(s):
  • Static analysis tools
  • VC++ 2015.3 v140 toolset for desktop (x86,x64)
  • VC++ 2017 v141 toolset (x86,x64)
  • Visual C++ Build Tools core features
  • Windows Universal C Runtime
  • if windows 10:
    • Windows 10 SDK (10.0.10240.0)
  • if windows 7 / 8 / 8.1
    • Windows Universal CRT SDK
    • Windows 8.1 SDK
  1. Start > Visual Studio 2017 > Developer Command Prompt for VS 2017 (run as administrator)
  2. execute command(s):
cd %VS2017BuildToolsDir%\Common7\Tools\
VsMSBuildCmd

2. Install LLVM

  1. download and run LLVM
  2. add to PATH for current/all user(s)

3. Remove redulant files

  1. run visual studio installer
  2. remove the following individual component(s):
  • VC++ 2015.3 v140 toolset for desktop (x86,x64)

4. Test LLVM

%procdir% = directory where you created proc.c

  1. create proc.c with
#include <stdio.h>

int main(void) {
    printf("Test\n");
    while(1) {}
    return 0;
}
  1. Start > Windows System > Command Prompt (run as administrator)
  2. execute command(s):
cd %ProcDir% 
clang -std=c89 proc.c -o proc.exe
proc.exe

Troubleshoot

'clang' is not recognized as an internal or external command, operable program or batch file.

You didn't select the set PATH for current/all user(s). If you did but it still didn't work, set the path environment variable manually by adding %LLVMInstallLocation%\bin

clang.exe: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]

You didn't install VC++ 2015.3 v140 toolset for desktop (x86,x64) and/or VC++ 2017 v141 toolset and/or run VsMSBuildCmd

@CapitanFuture
Copy link

Very helpful instruction for me !!

@Enache-Ionut
Copy link

This is very useful. Another way to use clang inside Visual Studio is Clang Power Tools. It's a VS extension: https://www.clangpowertools.com/

@ntrel
Copy link

ntrel commented Jan 4, 2021

https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017

This link doesn't seem to work any more. When I click on 'Tools for VS 2019' then the Download button for 'Build tools for VS 2019', it just takes me to the top of the page! This is so frustrating.

@ntrel
Copy link

ntrel commented Jan 4, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment