Convert MSBuild logs to compile_commands.json for C/C++ language servers
- What is ms2cc?
- Why is ms2cc useful?
- Requirements
- Installation
- Quick Start
- Usage
- Editor Configuration
- Troubleshooting
- LSP and AI: Better Together
- References
- License
ms2cc converts MSBuild build logs into compile_commands.json format. This compilation database is used by language servers, and various IDEs for code intelligence features (IntelliSense, navigation, refactoring, linting).
MSBuild does not generate compile_commands.json. ms2cc extracts compiler invocations from MSBuild's detailed logs and converts them to the standard format.
C and C++ language servers (like clangd, ccls, Microsoft C/C++, etc.) need a compile_commands.json file because they cannot correctly understand or parse your code without the exact compiler flags that are used when building the project.
Unlike languages such as Rust, Go, Python, or Java, C and C++ code is not self-describing. A C/C++ source file:
- depends on preprocessor macros
- depends on include paths (-I)
- depends on system headers
- can change behavior based on platform and compiler
- may use language extensions (-std=gnu++20, -fms-extensions)
- may be compiled differently per file
This means the same .cpp file can produce totally different ASTs depending on its flags.
A language server must replicate the exact compiler invocation, or it literally cannot parse the file in the correct configuration.
- Platform: Windows (Windows 10/11, Windows Server)
- Build System: MSBuild (Visual Studio 2019, 2022, or Build Tools)
- For Building from Source (optional): Rust toolchain
-
Download:
- Visit the releases page
- Download the
ms2cc-x.x.x.zipfile
-
Extract:
- Unzip the file to extract
ms2cc.exe
- Unzip the file to extract
-
Usage:
- Run it from anywhere by adding the directory to your PATH, or
- Copy
ms2cc.exeto your project directory
-
Install Rust (if not already installed):
# Visit https://rustup.rs and follow the instructions -
Clone the repository:
git clone https://github.com/freddiehaddad/ms2cc.git cd ms2cc
-
Build the release version:
cargo build --release -
Find the executable:
The built executable will be at: target\release\ms2cc.exe
cd C:\path\to\your\project
msbuild YourSolution.sln /v:detailed > msbuild.logThe /v:detailed flag is required. Without it, MSBuild doesn't log enough information.
Visual Studio IDE: In Visual Studio 2019/2022 use Build > Project Only > Build Only ProjectName. When the Output window finishes scrolling, right-click inside it, choose Save Build Log, and save it as
msbuild.logwith MSBuild Project Build Log (*.log).
ms2cc -i msbuild.log -o compile_commands.jsonSee the Editor Configuration section below for your specific editor.
Test-Path compile_commands.json
Get-Content compile_commands.json | Select-Object -First 8The file should exist and contain one JSON object per compiler invocation, for example:
[
{
"file": "src\\main.cpp",
"directory": "C:/path/to/your/project",
"arguments": ["cl.exe", "/Iinclude", "src/main.cpp"]
}
]If the file is missing or empty, revisit the logging step.
ms2cc supports several options for customizing behavior:
# Basic usage (uses defaults: msbuild.log → compile_commands.json)
ms2cc
# Specify custom input and output paths
ms2cc -i build\debug.log -o compile_commands.json
# Pretty-print the JSON output (useful for viewing/debugging)
ms2cc -i msbuild.log -o compile_commands.json -p
# Quiet mode (only show errors)
ms2cc -i msbuild.log -o compile_commands.json -l error
# Disable progress bars (useful for scripting)
ms2cc -i msbuild.log -o compile_commands.json --no-progress
# Show all available options
ms2cc --help
# Show version
ms2cc --version| Option | Description | Default |
|---|---|---|
-i, --input-file <FILE> |
Path to MSBuild log file | msbuild.log |
-o, --output-file <FILE> |
Path to output compile_commands.json | compile_commands.json |
-l, --log-level <LEVEL> |
Logging level (off, error, warn, info, debug, trace) | info |
-p, --pretty-print |
Pretty-print JSON output | (disabled) |
--no-progress |
Disable progress bar output | (progress bars enabled) |
-h, --help |
Display help information | - |
-V, --version |
Display version information | - |
Once you've generated compile_commands.json, configure your editor to use it.
Note: The
compile_commands.jsonfile should be in your project root directory.
-
Install the extension
- Open Extensions (
Ctrl+Shift+X) - Search for "C/C++"
- Install the official Microsoft C/C++ extension
- Open Extensions (
-
Configure
Create or edit
.vscode/c_cpp_properties.json:{ "configurations": [ { "name": "Win32", "compileCommands": "${workspaceFolder}/compile_commands.json", "intelliSenseMode": "windows-msvc-x64" } ], "version": 4 }Note: You can place the
compile_commands.jsonfile in the.vscodedirectory if you prefer:{ "configurations": [ { "name": "Win32", "compileCommands": "${workspaceFolder}/.vscode/compile_commands.json", "intelliSenseMode": "windows-msvc-x64" } ], "version": 4 } -
Reload VSCode
Press
Ctrl+Shift+P, type "Reload Window", and press Enter. -
Confirm the setup by opening a C/C++ file, pressing
Ctrl+Shift+P, runningC/C++: Log Diagnostics, and making sure the output reports no parsing or IntelliSense errors.
-
Install the clangd extension
- Open VSCode Extensions (
Ctrl+Shift+X) - Search for "clangd"
- Install the official
llvm-vs-code-extensions.vscode-clangdextension - If prompted to download clangd, click "Download"
- Open VSCode Extensions (
-
Disable Microsoft C++ IntelliSense
Create or edit
.vscode/settings.jsonin your project:{ "C_Cpp.intelliSenseEngine": "disabled", "clangd.arguments": [ "--compile-commands-dir=${workspaceFolder}", "--background-index", "--clang-tidy" ] } -
Reload VSCode
Press
Ctrl+Shift+P, type "Reload Window", and press Enter.
Note for MSVC Projects: For optimal clangd compatibility with MSVC code, copy
.clangd.templateto.clangdin your project root. This configuration suppresses common MSVC-specific warnings. See Using clangd with MSVC Projects for details.
Most modern editors have excellent clangd support. For detailed setup instructions including:
- Neovim
- Zed
- Cursor
- Helix
- Other LSP-compatible editors
See the Using clangd with MSVC Projects guide for complete configuration examples, compatibility information, and troubleshooting.
Quick clangd setup:
- Generate
compile_commands.jsonwith ms2cc - (Optional but recommended) Copy
.clangd.templateto.clangdin your project root - Configure your editor to use clangd (see guide for editor-specific examples)
Cause: MSBuild log doesn't have enough detail.
Solution: Ensure you used /v:detailed when building:
msbuild YourSolution.sln /v:detailed > msbuild.logPossible causes:
- MSBuild verbosity too low
- Some projects were skipped during build
- Incremental build didn't compile all files
Solutions:
- Use
/v:detailedverbosity - Do a clean rebuild:
msbuild YourSolution.sln /t:Rebuild /v:detailed > msbuild.log - Delete any stale
compile_commands.jsonfiles before regenerating, especially after switching configurations (Debug/Release, Win32/x64)
Solution:
-
Ensure
compile_commands.jsonis in your project root directory -
Check your editor configuration (see Editor Configuration)
-
For clangd, verify it's installed and accessible:
clangd --version -
Reload/restart your editor
Cause: Multiple IntelliSense engines running simultaneously.
Solution (VSCode): Disable Microsoft C++ IntelliSense when using clangd:
In .vscode/settings.json:
{
"C_Cpp.intelliSenseEngine": "disabled"
}Solution:
- Download clangd from https://github.com/clangd/clangd/releases
- Add to your PATH, or configure the full path in your editor settings
Cause: clangd reports some MSVC-specific warnings that aren't relevant (e.g., #pragma optimize, missing field initializers).
Solution: Use the provided .clangd configuration template:
- Copy
.clangd.templateto.clangdin your project root - Customize as needed (see comments in the template)
- For detailed information, see Using clangd with MSVC Projects
The template suppresses common MSVC-specific warnings while keeping important diagnostics.
With the rise of AI-powered coding assistants, some developers believe LSP is antiquated. However, LSP remains essential for high-quality code intelligence for several reasons:
-
They provide deterministic, real-time guarantees
The Language Server Protocol gives editors fast, reliable, incremental features such as:
- autocompletion
- hover info and signature help
- diagnostics in real time
- semantic tokenization
- symbol indexing
- "go to definition" and cross-reference analysis
These features work because LSP servers maintain an up-to-date AST, symbol tables, type information, and can react within milliseconds.
LLM-based agents cannot match that determinism or sub-50 ms latency reliably, especially on larger codebases.
-
LSP understands project semantics in a ways LLMs cannot match
Even with retrieval or agent-based navigation, LLMs still:
- lack precise understanding of type systems
- can hallucinate unseen functions or APIs
- struggle with multi-file, incremental code state
- cannot maintain a full AST-level view the way a compiler or language server can
LSPs plug directly into the compiler toolchain; that precision is not replaceable by probabilistic models alone.
-
Agents build on top of LSP features -- not instead of them
Modern coding assistants (GitHub Copilot, Cursor AI, Codeium, Windsurf, Zed AI, etc.) typically use:
- LLM (reasoning + generation)
- LSP (semantic signals, types, diagnostics)
- Indexers (global symbol search, embeddings)
LLMs work best when they are grounded in deterministic data -- and LSP is the grounding layer.
Agents rely on:
- LSP diagnostics to know what's broken
- LSP symbol info to find definitions
- LSP semantic tokens to reason about structure
- LSP type information to provide accurate code suggestions
If LSP didn’t exist, coding agents would be worse, not better.
That's why ms2cc exists -- to ensure your C/C++ projects have the LSP foundation that makes both manual coding and AI assistance better. Run ms2cc whenever you regenerate build logs so compile_commands.json stays fresh as projects, configurations, or toolchains change.
- Language Server Protocol (LSP)
- clangd - C/C++ Language Server
- clangd Configuration
- Using clangd with MSVC Projects
compile_commands.jsonFormat- Microsoft C/C++ Extension for VSCode
- MSBuild Command-Line Reference
- Visual Studio Build Logging
- Rust Programming Language
This project is licensed under the MIT License - see the LICENSE file for details.