
We recommend this mode of WSL development, where all your source code files, in addition to the compiler, are hosted on the Linux distro. Visual Studio Code has support for working directly in WSL with the WSL extension.
Note: Much of this tutorial is applicable to working with C++ and VS Code directly on a Linux machine. WSL is a Linux environment within Windows that runs directly on the machine hardware, not in a virtual machine. GCC stands for GNU Compiler Collection GDB is the GNU debugger. In this tutorial, you will configure Visual Studio Code to use the GCC C++ compiler (g++) and GDB debugger on Ubuntu in the Windows Subsystem for Linux (WSL).
Configure IntelliSense for cross-compiling. This seems to be the only way stop CMake from detecting MSVC. G Ninja -Bbuild -DCMAKE_C_FLAGS =TRUE -DCMAKE_CXX_FLAGS =TRUE -DCMAKE_C_COMPILER = "C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_CXX_COMPILER = "C:/Program Files/LLVM/bin/clang.exe" -DCMAKE_LINKER = "C:/Program Files/LLVM/bin/lld-link.exe"Īs you can notice I have to force the C and CXX flags to TRUE. The hackish solution I found that works with version 3.6.0 is to use the following command: cmake -H. The main problem I had to wrestle with was that CMake kept incorrectly detecting MSVC no matter what flags I set. My development setup relies on CMake and Ninja, but when it came to setting up Clang on Windows I had to hack around quite a bit to get it to work. I personally haven’t tried this, as I don’t use Visual Studio. To enable it follow the steps described in the official blog post. Using Clang with Visual Studio is straightforward if you use the version that comes bundled width the IDE. The following line will compile and link an executable that can be debugged on GDB: clang.exe -O0 -gdwarf -c test.cpp -o test.obj & lld-link -debug test.obj Using Clang with Visual Studio In order to make Clang emit DWARF debug symbols that GDB understands, you have to use the LLVM linker so you the full LLVM installation. It can be installed as part of Visual Studio 2015 and can be uses from the IDE or command-line. The former supports normal Clang-style command-line options, while the latter supports MSVC-style command-line options.Ĭlang with Microsoft Codegen, uses the Clang frontend and Microsoft’s MSVC backend to generate machine code, so it can output PDB files. It comes with two executables: clang.exe and clang-cl.exe.
LLVM Clang is, at the time of this writing, mostly feature complete but is not able to generate PDB debugging information. There are currently two flavors of Clang that work on Windows: vanilla LLVM Clang, and Clang/C2 with Microsoft Codegen. In this post I’ll talk about how you can setup Clang on Windows without having to cross-compile from Mingw or Cygwin. Clang is my compiler of choice as I found it to be the fastest for development and it works on all desktop platforms.