Skip to content

Compiling Cplusplus on Windows with Linux toolchain using Vim as a lightweight IDE and the Language Server Protocol

Spiros Kabasakalis edited this page Dec 23, 2018 · 2 revisions

Overview


This is just a short guide with references to online resources on how to set up a C++ Linux toolchain compilation and development environment on Windows (targeting Windows) using Vim as a lightweight IDE.

Prerequisites

Install MSYS2


Installing MSYS2 creates a unix-like dev environment on windows with clang and gcc compilers plus related tools. Note, several clang tools are not included in the pre-installed libraries, you may need to install LLVM for windows, separately from MSYS2 just to get those clang tools and include them in your system's path.

Resources:


C/C++/ObjC language server supporting cross references, hierarchies, completion and semantic highlighting.

Code completion (with both signature help and snippets), definition/references, and other cross references, cross reference extensions: $ccls/call $ccls/inheritance $ccls/member $ccls/vars, formatting, hierarchies: call (caller/callee) hierarchy, inheritance (base/derived) hierarchy, member hierarchy, symbol rename, document symbols and approximate search of workspace symbol, hover information, diagnostics and code actions (clang FixIts), semantic highlighting and preprocessor skipped regions, semantic navigation: $ccls/navigate.

Resources:

Install Vim for Windows: Installers


Install Spacevim


Asynchronous linting/fixing for Vim and Language Server Protocol (LSP) integration ALE


I use ALE for linting with clang-tidy, and code formatting with clang-format

Install Vim Language Server Protocol client coc.nvim


I use coc.vim to provide vim with all other LSP IDE features (leaving only formatting and linting to ALE).




Convenient vim key bindings for these tasks are configured in my cpptaks.vim file


Note that it's essential to have a compile_commands.json file in the root of your project for LSP features to work. This file is produced as a byproduct of the cmake compilation with the help of a flag. See tasks folder in sfml-project. Library dependencies of your cpp projects can be installed in your MSYS environment with the help of the pacman package manager.

This is just a brief (but complete) outline of the setup, it's up to you to work out the details with the help of the linked resources.