Creating llvm/clang Linux projects with Visual Studio

This tutorial shows how to create, build and debug a Linux application using the clang compiler under Visual Studio with VisualGDB.

  1. Install VisualGDB on your Windows machine with Visual Studio. Start Visual Studio, select File->New Project->VisualGDB->Linux Project Wizard:01-newproj
  2. On the first wizard page select “New Application”:02-application
  3. Select a computer where you want to run clang. If you have troubles setting up the SSH connection, follow the Linux quickstart manual.02-compsel
  4. If you don’t have clang installed, or are unsure about it, click at the terminal icon to the right from the computer selection. A new terminal window will open. Run the following command to install clang on your Debian-based Linux system:
    sudo apt-get install llvm clang

    If you are using a Red Hat-based system instead, use yum to install LLVM/clang.03-installclang

  5. The terminal window is running in a separate process, so you can safely go back to the wizard and keep it running in the background. Once you press the “Next” button in the wizard, VisualGDB will automatically test your toolchain:05-test
  6. The last wizard page allows customizing the way source files are transferred between the Windows and the Linux computers. The easiest way is to accept the default settings:06-filetransfer
  7. When you press Finish, VisualGDB will create a new Visual Studio project for you. Press Ctrl-Shift-B to build it. You will see how clang is invoked in the background:07-build
  8. Set a breakpoint anywhere in the code and press F5 to start debugging. When a breakpoint is hit, right-click anywhere in the source code and select “Go to disassembly”:08-disasm
  9. You can use the disassembly view to see the source code and the corresponding disassembler dump:09-optionsUse the context menu to set various disassembly options and select which information to show.
  10. You can easily modify the compiler flags by editing the flags.mak file:10-flags